Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chosen Multiple reset doesn't work #1679

Closed
piercemcgeough opened this issue Dec 4, 2013 · 5 comments
Closed

Chosen Multiple reset doesn't work #1679

piercemcgeough opened this issue Dec 4, 2013 · 5 comments

Comments

@piercemcgeough
Copy link

Using the line $(".chosen-select").val('').trigger("chosen:updated"); in a jquery script does not reset the chosen form field. It works ok for the single dropdown though.

@koenpunt
Copy link
Collaborator

koenpunt commented Dec 4, 2013

Try the following:

$('.chosen-select option:selected').removeAttr('selected');
$('.chosen-select').trigger('chosen:updated');

@piercemcgeough
Copy link
Author

Tried that but the html that gets generated for the multiple is different from the single select.
This is it here.

<div class="chosen-container chosen-container-multi" style="width: 100%;" title="" id="users_chosen">
  <ul class="chosen-choices">
    <li class="search-choice">
      <span>Manus </span>
      <a class="search-choice-close" data-option-array-index="1"></a>
    </li>
    <li class="search-field">
      <input type="text" style="width: 25px;" autocomplete="off" class="" value="Choose users...">
    </li>
  </ul>
  <div class="chosen-drop">
    <ul class="chosen-results">
      <li data-option-array-index="1" style="" class="result-selected">Manus </li>
      <li data-option-array-index="2" style="" class="active-result">Owen </li>
      <li data-option-array-index="3" style="" class="active-result">Sean </li>
      <li data-option-array-index="4" style="" class="active-result">Sinead </li>
    </ul>
  </div>
</div>

@sudhirke
Copy link

sudhirke commented Feb 7, 2014

Thanks a lot for this, I was looking out for this option and had posted on the StackOverflow site, but didin't get any reponse. Looks like this forum is more active 👍

@markusguenther
Copy link

I tried to reset the whole form with something like that:

        var form = $('form');
    form.get(0).reset();
    form.find('.filterSelect').trigger('chosen:updated');

But i have the similar problem ... for the single drop downs everythings works fine. But the multiple selects don`t have a placeholder anymore.

@koenpunt
Copy link
Collaborator

koenpunt commented Oct 15, 2016

Multi-selects expect an array as value, so to reset it using jQuery you can use the following:

$('.chosen-select').val([]).trigger('chosen:updated')

See here for a live example: https://jsfiddle.net/koenpunt/L1sd259w/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants