Jquery autocomplete UI , Populating key instead of value - jquery-autocomplete

enter code hereI am using jquery autocomplete ui.
I have a text box in which user types name of a US state and autocomplete suggestions are made. Here an ajax call is made and json results are returned as expected.
eg. when user types "new" , the json response returned is:
{"NH":"New Hampshire","NJ":"New Jersey","NM":"New Mexico","NY":"New York"}
What i want is when user clicks a state from the suggest list , eg "New York" , instead of populating the text box with the state name , its state code ("NY" here) be populated.
my current code is :
$("#selectAllStateList").autocomplete( { source: "getStateList.html"
});
*******Update ***
Ok .. now so I have changed the response format . So when I type "de" , I get the response.
[{"label":"DE","value":"Delaware"},{"label":"RI","value":"Rhode Island"}]
The autocomplete suggestion box shows me DE and RI , but when I click on RI , Rhode Island gets populated in the text box instead of RI which I want.
Can someone help me how to do that.
Thanks in anticipation
Rachit

Got it .. simply changed labels with values.

Related

Blue Prism Write to Web Client

Has anyone had any problems writing data to a web client data field?
Having spied the field to be written in, the write action correctly writes the value from the data item into the web field. We then "Save" the value in the field by clicking the Save button. This is when the value reverts back to the value that was previously in the field and does not save the new value.
Copying the value from the data item and pasting it directly into the web field and hitting save works fine, but for some reason when Blue Prism does the write action and then save, the new value is not saved.
Any suggestions?
This is probably due to the way the web application is coded - specifically, the data in the box is not acknowledged until a keydown event (or similar) is fired. When you copy/paste the data into the field, it fires a similar event where it believes the user to have interacted with the field.
The solution for this type of field is to use the Send Keys or Global Send Keys functionalities of Blue Prism to send the desired text.
It happens when the target application uses java script events to sense the changes in the element. To handle this , you have to use the send keys in following format.
1. Focus the application / Control
2. Send Global mouse click centre to the element
3. Send "Sendkeys" to the application now.
4. Focus a dummy element in the page to let the page sense your input.
If the old value is already higlighted when the spied field is selected, try getting BP to delete it first, then paste in the new value, then click on the field again, then save. If this doesn't work, then uncheck the URL attribute of the application model you are using for the spied field and try this again.

Refresh edit box after information change

I have edit box which has validation- it is required field and it has range of values validation as well. The validation works ok, but the problem is that error message does not dissapear when I replace the values in edit box with valid ones. I tried to add full update on onchange event but this is not a option for me since this changes other fields in my xpage as well. The partial update on the field does not work. Any advice how to refresh the field so that error message dissapears?
Create a wrapper panel or div around BOTH the field and the error message control and set it's ID to the one that should be partially refreshed. I assume you use
XSP.partialRefreshGet("#{id:idOfYourField}")
in the onblur client event!? So just change the ID name here.

Lightswitch Search screen - choosing what you can search by

I have a search screen which shows results from a 'projects' entity. One of the fields is a link to a 'Clients' entity, which has a client name.
I can use the search box above the data to search by project name, date, etc but I cannot search by client name. i guess because it is actually a reference to a seperate entity.
How can i make it so that I can search for projects, using the search box, by client name?
To try to explain clearer here is the database layout.
Project
------
ProjName
ProjType
ProjComment
Client --------------- Client
-----
Name
Address
I can search by the project fields, but not the client name.
Create a custom query for Project entity and add optional parameters for all the Project and Client properties that you wish to search for. Wire up the custom query filter.
For full control do not wire up the custom query filter, instead filter in code behind, the PreProcess event.
if your using the HTML Client it can be done as follows on a browse screen associated with in your case the Project Table. if you look at the left navigation bar, click on edit query and within here, you can see 3 options, Filter, Sort and Parameters.
Filter should say Client.Name based on your table structure, the second should be changed to "contains", the 3rd should be set as parameter and finally the 4th box is where you create the new parameter you are going to use as a search box...
you can rename the Parameter at the bottom and I always find its best when on this, to set it as optional in the bottom right property box. (This means all the data will be displayed rather than nothing until searched)
Now if you were to go back to your main screen page, drag this parameter from the left onto the main screen page and set it as a text box. Using this and pressing enter after you have typed something will display the results that match what you have typed so far.
a little more to the above, if you were to click "Edit PostRender Code" and add the below then after 3 characters are entered, the table list your searching through will be updated automatically after each finger stroke...
$searchBox = $("input", $(element));
setTimeout(function () {
$searchBox.focus();
}, 1);
onInputAsYouType(element, 1, function (text) {
contentItem.screen.[CREATED PARAM NAME] = text; //SearchText here is the data item in the screen designer linked to the query parameter
});
function onInputAsYouType(element, numberOfRequiredChars, done) {
var inputbox = $("input", $(element));
inputbox.on("input", function (e) {
var text = $(this).val();
if (text.length >= numberOfRequiredChars)
done(text);
});
};
};

When hand-coding CodedUI Tests, is there a way to clear text inputs before populating them?

My goal is to clear text inputs before populating them.
For example, I am populating form fields using:
Keyboard.SendKeys(myInput, "Some Text");
My form populates fields on page load using cookie values.
When I try to use CodedUI to populate the email field, it appends a string to the current value instead of adding the desired value only.
My goal is to use CodedUI to populate the email field with:
foo#bar.com
But, since the field is already aaa#bbb.com (populated with cookie data on page load), it ends up being:
aaa#bbb.comfoo#bar.com
This worked. Set the text property before sending keys:
myInput.Text = "";
Keyboard.SendKeys(myInput, "Some Text");
You could try to double click the field to select all text, when the text is selected it will be overwritten.
Mouse.DoubleClick(myInput)
Maybe better is to clear the cookies before each test run
BrowserWindow.ClearCookies()
I've used the following with success:
control.SetFocus();
Keyboard.SendKeys("a", System.Windows.Input.ModifierKeys.Control);
Keyboard.SendKeys("{Delete}");
Keyboard.SendKeys(control, value);

In crm 2013 the AttributeInfo.GetValue returns wrong value

We are experiencing a strange issue, which can be reproduced by following below steps:
Open New Task (Or any other entity)
Enter text “Test Subject” in “Subject” field (or use any other field).
Use this Xrm.Page.getAttribute("subject").getValue(); statement to
get the value of subject’s field, it will return “Test Subject”.
Now clear the subject field.
Use this Xrm.Page.getAttribute("subject").getValue(); statement to
get the value of subject’s field, it will return “Test Subject”,
which is wrong value, the subject field is empty.
The Xrm.Page.getAttribute("subject").getValue() returns wrong value. We checked this issue in CRM 2011 and its ok the issue is specific to CRM 2013.
EDIT:
This code is fired from Custom Ribbon Button.
We tried to change the focus to another control and then we checked the value, it not works.
EDIT:
This issue occurs only if the field is a required field.
The logic of CRM page is that it changes data inside of the Xrm.Page.data object only if the edited field lost focus (this event tells CRM that the data entry is done), so it could be that after step 4 you don't lose focus to other field. This behavior is the same as in CRM 2011.
I think you have two problems here although they maybe cause by the same thing. This is unfortunately not an answer to these problems but an attempt to clarify the above.
Problem 1: JavaScript reads previous value when an empty value is entered.
I think this is the same as the original problem of this post.
This is also posted at: http://partnersupport.microsoft.com/en-us/mpndynamics/forum/mpndyncrm/javascript-reads-previous-value-when-an-empty/f7b8dffd-3a21-48ae-8dca-4c5467ea8272
On the Competitor form.
Enter “Oliver” in the name field.
Then read it in JavaScript as below.
function ClickHandler()
{
var nameValue = "";
nameValue = locationValue = parent.Xrm.Page.getAttribute("name").getValue();
var test1 = "";
}
You should get “Oliver” as expected.
Then go back to the Competitor form and manually delete the text with the backspace key.
Now read what is in the name field with JavaScript as was done earlier.
You would expect to get nothing but you get “Oliver”.
Now enter Mark in the name field.
Read the field with JavaScript and you get “Mark” as you should.
So it seems when an empty value is entered following a previous value the JavaScript reads the previous value.
To put it a different way. It seems that there is a problem if the Name field had a value and the text then gets manually deleted. The Xrm.Page object will not update to the empty string. The Xrm.Page object will however update to a non-empty value.
Problem 2: Javascript cannot read the value in the text field if the field has not lost focus.
This is also posted at http://partnersupport.microsoft.com/en-us/mpndynamics/forum/mpndyncrm/javascript-cannot-read-the-value-in-the-text-field/ecc2c9e0-fba0-44f2-93cd-320d042896f0?tm=1389885238744
Javascript cannot read the value in the text field if the field has not lost focus.
On the "Recurring Appointment" form I have an IFRAME that runs Javascript. It reads the value in the location field when a button is pressed. If I change the value in the location field to say "Brunswick Street" and press the button I get nothing read (i.e. in the code below locationValue is null).
However if I change the value in the location field to say "Brunswick Street". I then then click away to somewhere on the form other than the IFRAME so the location field has lost its focus (this can also be achieved by pressing enter/tab after entering the text in the location field). If I then press the button on the IFRAME the Javascript will read the text in the location field correctly.
I gather that this is because parent.Xrm.Page is only updated when focus is lost in a field.
function ClickHandler()
{
var locationValue = parent.Xrm.Page.getAttribute("location").getValue();
}
I tried changing the focus in the JavaScript by setting it to requiredattendees field. But this did not work.
parent.Xrm.Page.getControl("requiredattendees").setFocus();
I used to use parent.document.forms[0].namedItem(srcDataFlds[fld]).value; to get the value in CRM 4 and 2011 but this does not work in CRM 2013. So as the SDK suggested I changed the code to use parent.Xrm.Page however it seems to give the problem above.
The questions are why is the focus not lost when I click the button on the IFRAME? If I click on any field in the form the focus changes so why not the IFRAME.
Also how can I get the JavaScript to read the value in the location field without having to click away from the location field. (Hopefully read the value in a supported way)?
I just want the user to be able to enter the value in the location field and click the button in the IFRAME.
I also noticed that when you click the IFRAME the On Change Event is not fired for the location field.
So far the only way round this is to click on another field (or pressing enter/tab) before clicking on the button that fires the Javascript.
Both these problems have been recognized by Microsoft and have been fixed in “Update Rollup 1 for Microsoft Dynamics CRM 2013 Service Pack 1”

Resources