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!
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
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:
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.
Hello Hristo, thank your help.With your questions about idea of the code in the DropDownClosing event:
I want when I search on the dropdown. If the search results are 2 items, the 2nd item must be selected automatically without the user to select that item. If the search results more than 2 items. the user does not select item. webdropdown will set selected item value before search.
1) I want to programmatically select an item.2) When user close dropdown and don't selecte item. webdropdown will be set selected item.
In addition I have checked your code. it is true when the user selects one item but does not help in my case.
Please help me, thank you very much!
Thank you for your answers.
I assume that by "search results" you mean the items visible in the drop down list. I hope I have understood you correctly and I have slightly changed the function you execute in order to work for your scenario.
Please have a look and let me know if there is something I am missing or I did not understand.
Here is a brief overview how this function works when closing the drop down:
1) If there is any item active(selected), its value and text are assigned to the HD_Entity_ID and HD_Entity_Name inputs. // line 3 - 12
2) If no item is active(selected) // line 26
I hope this helps. Please let me know if this logic correctly follows your scenario of if it needs some changes.
Hi Hristo
i has fixed my code. it's work very good. thank you very much :)
I wanted to ask a little more:
when i enter "123_" on dropdown. search results have 2 item (blank and 123_guarantor)
click out dropdown, the item "123_guarantor" must be selected.
my program run not ok with first.
Please see new demo behind and help me fix that
Hi Hristo, It worked out great. Thanks for your help ^^!!!
Please leave the return at line 63 and set the AutoSelectOnMatch property of the WebDropDown to false like this:
AutoSelectOnMatch="False"
Now you should be able to select blank item and if you do not the second item will be selected when there are two items in the list.
Please test it and let me know if it meets your requirements now. If you have any further questions, please do not hesitate to contact me, I will be glad to help.
Hi Hristo. Thank you for your answers
if i don't put return on line 63, i don't select blank item.
i want when i select blank item, the function must be stopped without regard to search results( the items in the dropdown) are two or more than two
Please help me fix that. Thank you!
Thank you for your sample. I reviewed and noticed that you have placed return; on line 63 - when this line executes your function stops here and below code does not execute. I have removed this line and now it works as expected. Please review the sample I have attached - I have only put this line in comment, everything else is the same.
I have also included comment to line 65 - please have a look.
I hope this helps.