jQuery UI Widgets Forums Lists DropDownList Clearing Selection

This topic contains 5 replies, has 3 voices, and was last updated by  jbpd 10 years, 11 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • Clearing Selection #4301

    Daniel
    Member

    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

    Clearing Selection #4304

    Peter Stoev
    Keymaster

    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 Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Clearing Selection #4335

    Daniel
    Member

    Thanks alot. This worked… I was still using 1.9 before.

    Btw. it also works without the boolean parameter.

    Clearing Selection #4947

    jbpd
    Participant

    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

    Clearing Selection #4974

    Peter Stoev
    Keymaster

    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 Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Clearing Selection #4985

    jbpd
    Participant

    that worked perfect. Thanks, Jeremy

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.