javascript - jQuery Chosen dynamic update keeping existing selections - Stack Overflow

I am using Chosento populate a select list.When a user selects an item from the list, it will then g

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
Add a ment  | 

2 Answers 2

Reset to default 4

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;
  }

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745575751a4633953.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信