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

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

本文标签: javascriptjQuery Chosen dynamic update keeping existing selectionsStack Overflow