-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Possible to update Chosen's selected values? #1270
Comments
I believe that I'm having the exact same issue as well. I am removing all of the options from the native select element and I'm looking to regenerate the Chosen select. This functionality does work in older versions of Chosen (I tested it using the version from the documentation). It looks like the current master has a change in Chosen.prototype.results_build in regards to the way Chosen counts selected choices:
It looks like it thinks there are no choices selected, so there is nothing to remove (which might be the case within the HTML select, but not Chosen's UI). Removing the choice_count() check in the if statement seems to resolve it, but I'm not sure if that would have adverse effects otherwise. Perhaps it's unnecessary since the jQuery remove call that it executes would still be fine even if there was nothing to remove. The following commit might be to blame: a469c43 |
Thanks for the workaround Kyle. I'm not seeing any adverse effects so far. |
You should not update an object's attributes this way (this helpful stack overflow thread gets into why). If you're just looking to blow away all selections, jQuery's val function makes this easy: $("field").val("").trigger("liszt:updated") |
@pfiller , there is definitely a bug here. Please see this fiddle. If you click "Reset" to remove the selections, Chosen doesn't update properly. It looks like it's only a problem with multiple type select inputs. Whether I remove the "selected" attribute or unset the value of the select, the problem remains the same. |
@KyleJSummers Weird. Something seems to have been introduced between 0.9.14 and 0.9.15 that broke this functionality. Good times! |
Thanks @KyleJSummers - this is now resolved in master. |
I'm doing something like this in jquery:
var obj = $("select[name='myselect']");
obj.find('option').removeAttr('selected');
obj.trigger("liszt:updated");
I would expect that to update the list and remove all selected options. It does appear to be updating the list logically, but it's not updating the UI to reflect the deselected options. It simply shows the previously selected options with the data-placeholder text next to it (which I assume means the field is logically empty).
The text was updated successfully, but these errors were encountered: