jQuery UI Widgets › Forums › Lists › DropDownList › Clearing Selection
Tagged: DropDownList, jQuery DropDownList
This topic contains 5 replies, has 3 voices, and was last updated by jbpd 10 years, 11 months ago.
-
AuthorClearing Selection Posts
-
Hi,
I need to get the DropDownList back to its initial state where no item is selected and the DropDownList widget itself is empty again. I do not want to remove the items (change the source).
I expected ‘clearSelection’ to do the job, but it actually does nothing obvious. Also ‘unselectIndex’ does not work.
Btw calling a non-existing method does not generate any errors. Is that wanted?
Daniel
Hi Daniel,
You can use this code to clear the selection with jQWidgets 2.1
<script type="text/javascript"> $(document).ready(function () { var theme = getTheme(); var source = [ "Affogato", "Americano", "Bicerin", "Breve", "Café Bombón", "Café au lait", "Caffé Corretto", "Café Crema", "Caffé Latte", "Caffé macchiato", "Café mélange", "Coffee milk", "Cafe mocha", "Cappuccino", "Carajillo", "Cortado", "Cuban espresso", "Espresso", "Eiskaffee", "The Flat White", "Frappuccino", "Galao", "Greek frappé coffee", "Iced Coffee", "Indian filter coffee", "Instant coffee", "Irish coffee", "Liqueur coffee" ]; // Create a jqxDropDownList $("#jqxWidget").jqxDropDownList({ source: source, selectedIndex: 1, width: '200', height: '25', theme: theme }); $("#jqxWidget").jqxDropDownList('clearSelection', true); });</script>
Calling non-existing methods would not generate any result by design.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comThanks alot. This worked… I was still using 1.9 before.
Btw. it also works without the boolean parameter.
It clears it to the user, yes.
My issue is that I get the selected index, clear it, get the selected index again and they are the same.
Ex:
I default select the first item, index is 2
I clear the box….to the user, there is nothing selected
I get the selectedIndex and it shows an index of 2….how do I clear this out.I am trying to select a user, but after an action, I want to reset it. I can’t accomplish this when it won’t clear it out.
Thanks, Jeremy
Hi Jeremy,
The behavior you encountered should not work like that. The workaround which you can use is to set the selectedIndex when the jqxDropDownList’s ‘clearSelection’ is called.
Example:
$("#jqxWidget").jqxDropDownList('clearSelection');$("#jqxWidget").jqxDropDownList('selectedIndex', -1);var index = $("#jqxWidget").jqxDropDownList('getSelectedIndex');
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comthat worked perfect. Thanks, Jeremy
-
AuthorPosts
You must be logged in to reply to this topic.