I must be doing something wrong since for the asp.net DropDownList, I only needed 1 line of code.
ddlX.options[i].selected = true;
Converting over to an ig control has been a lot of work. 1st my DropDowns are in a WebDialogWindow that starts off hidden which messes up the z-axis so I run the following:
{
sender.behavior.set_zIndex(200000);
}
(err) {
alert(
'unable to initialize drop down' + err.description);
Then, in order to change the current selection I have to run the following routines:
function ddlClearSelection(ddl) {
for (var ix = 0; ix < ddl.get_items().get_length(); ix++) {
var item = ddl.get_items().getItem(ix);
if (item != null) {
item.unselect();
item.inactivate();
return false;
ddlClearSelection(ddl);
ddl.set_selectedItemIndex(indx);
ddl.set_activeItemIndex(indx);
ddl.set_currentValue(ddl.get_items().getItem(indx).get_text(),
true);
ddl.get_items().getItem(indx).select();
ddl.get_items().getItem(indx).activate();
ddl._elements.Input.value = ddl.get_items().getItem(indx).get_text();
The markup for one of the WebDropDowns is as follows:
<
ig:WebDropDown ID="DropDownListAccountGroup2" runat="server" Width="200px" DropDownAnimationDuration="100" DisplayMode="DropDownList" EnableDropDownAsChild="False">
<ClientEvents Initialize="ddlInitialize" />
<ClientEvents SelectionChanged="ddlAcctGrpChng2" />
</ig:WebDropDown>
Hi,
If you want to select an item on the client, you need to do:
dropDown.get_items().getItem(i).select();
Yep, this won't update the input value or deselect other items. If you want to mark all other items as not selected, you can use this function:
dropDown.__unselectAllItems();
I am not sure why you need to change activation. Activation should only be used when the end user browses through the items with mouse and or keyword, and it is mostly useful when multiple selection is enabled.
Alternatively, you can use the following code:
dropDown.__singleSelect(null,newItem,oldItem); // this will update the selected item index as well.
We will consider adding a function selectItem() to the dropdown client-side class, that will simulate a mouse click on the item. I have created a work item for this functionality, the number is: 24657
Will let you know when it's done.
Thanks,
Angel
I attempted to use dropDown._unselectAllItems() but an error was returned.
Object doesn't support this property or method
it was listed in the Methods in the Locals browser.
Updated code section:
ddl._unselectAllItems();
//ddlClearSelection(ddl);
The function has two underscores, not one, i.e. "__unselectAllItems()" instead of "_unselectAllItems"
Hope it helps,
__unselectAllItems() did not un-select all items on the client side. I am continuing to use my above workaround.
But thank you for the input,
Matt