admin管理员组文章数量:1023867
I am using 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
I am using Chosen http://harvesthq.github./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
Share Improve this question asked Jan 24, 2012 at 15:43 JaredeJarede 3,4986 gold badges47 silver badges75 bronze badges 4- you want to edit the list of options after the user has already selected some of them. If I read the docs correctly, it's not supported at the moment. – Marcelo Diniz Commented Jan 24, 2012 at 16:02
- yep thats what I want to do. I'll have to go back to the old fashioned way then if it's not supported. – Jarede Commented Jan 24, 2012 at 16:05
- you can fork their project and make a patch, it should be a matter of keeping the selected options instead of getting rid of them. – Marcelo Diniz Commented Jan 24, 2012 at 16:07
- i might try, not sure my javascript is good enough though. – Jarede Commented Jan 24, 2012 at 16:09
2 Answers
Reset to default 4You 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;
}
ment 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")
Having put a request on the chosen github issues page, they have decided not to add this functionality
https://github./harvesthq/chosen/issues/467
I am using 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
I am using Chosen http://harvesthq.github./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
Share Improve this question asked Jan 24, 2012 at 15:43 JaredeJarede 3,4986 gold badges47 silver badges75 bronze badges 4- you want to edit the list of options after the user has already selected some of them. If I read the docs correctly, it's not supported at the moment. – Marcelo Diniz Commented Jan 24, 2012 at 16:02
- yep thats what I want to do. I'll have to go back to the old fashioned way then if it's not supported. – Jarede Commented Jan 24, 2012 at 16:05
- you can fork their project and make a patch, it should be a matter of keeping the selected options instead of getting rid of them. – Marcelo Diniz Commented Jan 24, 2012 at 16:07
- i might try, not sure my javascript is good enough though. – Jarede Commented Jan 24, 2012 at 16:09
2 Answers
Reset to default 4You 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;
}
ment 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")
Having put a request on the chosen github issues page, they have decided not to add this functionality
https://github./harvesthq/chosen/issues/467
本文标签: javascriptjQuery Chosen dynamic update keeping existing selectionsStack Overflow
版权声明:本文标题:javascript - jQuery Chosen dynamic update keeping existing selections - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745575749a2157008.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论