Hi Guys,
I am trying to select an item in the WebDropDown without clicking it. I see the methods to set an active item and also select an item by index. How can I use them?
I have this
var tmp = $find("LetterDropDown1");
var items = tmp.get_items();
var itemToSelect;
The "items" doesn't seem to be an Array. What I'm trying to do here is say I have a value ("99"), how do I find the item in the drop down who's value is "99" and then make that be the selected item? I want it to be like the user opened the dropdown and made a selection. How in the world can I do this? I fought tooth and nail to not use Infragisitcs controls in this project as there is so very little support and documentation, but nonetheless I was forced into using the WebDropDown here. Please proove me wrong and demonstrate good customer service and tech support and show a very simple example of how to accomplish this. Prefereably this week as the normal turn around seems to be weeks. Can you help me?
Thanks,
Kettenbach
Hi Kettenbach,
The API doesn't include a function to get an item by value on the client-side, but you can accomplish this in the following way (get_items() returns an object of type $IG.DropDownItemCollection):
var myItem = null;
for(i = 0; i < items.getLength(); i++)
{
var item = items.getItem(i);
if (item.get_value() == '99')
myItem = item;
break;
}
if (myItem)
tmp.selectItem(myItem);
or just tmp.selectItemByIndex(<some item index>);
or myItem.select(); // this will not activate the item and will not change the input value to match the item's text.
I hope you are also using the latest Service Release, to avoid any ambiguity about issues that are already fixed.
Please let me know if you need any additional help. Thank you,
Angel
Here is a generic function that you can paste into a utility.js file.
// Set the selected value of an Infragistics WebDropDown control// @param {String, Object} control: The ClientID of the WebDropDown control, or the result of $find('ClientID')// @param {String} value: The value to set. This is the value property, not text presented to the UI.// @return falsefunction setWebDropDownValue(control, value) {
if (typeof control == 'string') { control = $find(control); }
if (control) { var items = control.get_items(); var myItem = null;
for (i = 0; i < items.getLength(); i++) { var item = items.getItem(i);
if (item.get_value() == value) { myItem = item; break; }
if (myItem) { control.selectItem(myItem); } }
return false;