multiselect icon indicating copy to clipboard operation
multiselect copied to clipboard

Multiselect option is not updating

Open Davaasuren opened this issue 14 years ago • 5 comments

I dynamically added options in multiselect but mutliselect just has initial list items. how can I refresh mutliselect with new options.

Davaasuren avatar Apr 23 '11 18:04 Davaasuren

I have the exact same issue. I even mailed Yanick (one of the former contributers). He informed me that there used to be a refresh function in a previous version, but that it seems to be missing now.

PS: it tried the following: I used $('#hostess').multiselect('destroy'); to remove the multiselect. My logic being I would remove it, then update the select and finally add the multiselect again.

However the final step does not seem to be working. I just attached the multiselect again, without any luck : $("#hostess").multiselect();

this might help someone come up with a better solution (i hope)

mrRuben avatar Jun 10 '11 13:06 mrRuben

I found the solution. the multiselect has a remoteUrl parameter option. example:

$('#id_of_field').multiselect( { remoteUrl: "urlToFile.php" });

the 'urlToFile.php' needs to return data in the folowing format: value1 = option1 \n value2 = option2 \n ....

This worked for me.

mrRuben avatar Jun 14 '11 09:06 mrRuben

Will this work without a postback? How will it know to take another look if I have added more options to the database?

Thanks, Mark

angelfish avatar Nov 17 '11 11:11 angelfish

I'm afraid this doesn't work with the latest version anymore. I've just tried to implement this however there's no new option added. Also this solution doesn't work: https://github.com/michael/multiselect/issues/16#issuecomment-1032270

Anybody has a working example?


Here's what I tried furthermore:

$('.multiselect').append('<option value='+value+'>'+param+'</option>');

When I add all, the new appended option shows up in the selected list. After removing all it's also listed in the available list. However this doesn't make sense for practical use....


Finally got the solution!

create a new function in ui.multiselect.js like this: ..... }, refresh: function() { this._populateLists(this.element.find('option')); }, .....

use the code above and call the new refresh function afterwards: $('.multiselect').append('<option value='+value+'>'+param+'</option>'); $(".multiselect").multiselect('refresh');

Now the new option is added to the available list. All already selected options in the selected list remain the same.

carlos1001 avatar Nov 21 '11 14:11 carlos1001

Yes, yes, yes! Thank you carlos1001. This works GREAT! I cant tell you how pleased I am that you have took the time to provide this solution. Many Thanks!

angelfish avatar Nov 21 '11 21:11 angelfish