Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
245
issue get items when Webdropdown closing
posted

Hi all.

i have webdropdown search and loadondemand. 

when the search results are just one item. I want the item to be selected.

I've tried checking in DropDownClosing event. If there are 2 items (including blank item), the item second to be selected

but i can't get list item in this event or can't get value this item.

Please see demo behind and help me.

Thanks!

DdlProvider_LoadOnDemand.zip
Parents
  • 16310
    Offline posted

    Hello Nguyen,

    Thank you for your sample. I carefully followed your code and noticed this line:

     var item = sender._elements["List"].childNodes[1];

    This will return a

    • DOM element. Later you are trying to get the value and text by calling item.get_value() and item.get_text(), but these are not functions that you can run on DOM elements. Instead get the item this way:

    var item = sender.get_items()._items[1];

    and then item.get_value() and item.get_text() will return the correct results.

    Please see how this part of your code should look like:

    Code Snippet
    1. var itemSelected = sender.get_selectedItem();
    2. // next line will return true when the search results are 2 items (including blank item) and the selected item is the second item
    3. if (sender.get_items()._items.length == 2 && itemSelected.get_index() == 1) {
    4.     var item = sender.get_items()._items[1];
    5.     if (itemSelected != null) {
    6.         flagInit = true;
    7.         var olistItems = sender.get_items()._items;               // returns an array with the items
    8.         document.getElementById("HD_Entity_ID").value;           // correctly returns the value
    9.         if (itemSelected != null) {
    10.             document.getElementById("HD_Entity_ID").value = itemSelected.get_value();  // will return value of the selected item
    11.             document.getElementById("HD_Entity_Name").value = itemSelected.get_text(); // will return text of the selected item
    12.             document.getElementById("HD_SearchType").value = "";
    13.             sender.set_currentValue(itemSelected.get_text(), true);
    14.             return;
    15.         }
    16.         document.getElementById("HD_Entity_Name").value = itemSelected.textContent; // what do you try to get here ?
    17.         document.getElementById("HD_SearchType").value = "";
    18.         sender.set_currentValue(item.textContent, true);
    19.         return;
    20.     }
    21. }

    Apart from this I am not sure what is the whole idea of the code in the DropDownClosing event. If you clarify these for me maybe I will be able to rewrite the whole function inside:

    1) Do you want to check which is the selected item on dropDownClosing or you want to programmatically select an item ?

    2) What do you want to do if the 2nd item is selected or after you have selected it in code ?

    I hope this helps. If you answer my questions I will be glad to help you further.

Reply Children