Reputation: 3498
I am using Chosen http://harvesthq.github.com/chosen/ to populate a select list.
When a user selects an item from the list, it will then go off (json calls), find all options that relate to that option, remove those from the list and then repopulate the select box using:
$("#contacttribename").trigger("liszt:updated");
unfortunately, this then loses what the user has already selected. Is there a way of dynamically updating the list whilst keeping the users selections?
cheers
Upvotes: 1
Views: 4880
Reputation: 738
You can edit their existing code to make this possible.
Go to the chosen.jquery.js file and find the function declaration for Chosen.prototype.results_build
Within that function their should be an if statement:
if (this.is_multiple && this.choices > 0) {
this.search_choices.find("li.search-choice").remove();
this.choices = 0;
}
comment out the inner two lines like so:
if (this.is_multiple && this.choices > 0) {
//this.search_choices.find("li.search-choice").remove();
//this.choices = 0;
}
This will prevent existing selected choices from being cleared when calling
.trigger("liszt:updated")
Upvotes: 4
Reputation: 3498
Having put a request on the chosen github issues page, they have decided not to add this functionality
https://github.com/harvesthq/chosen/issues/467
Upvotes: 1