mysociety / jquery-multi-select

Converts <select multiple> elements into dropdown menus with checkboxes
https://www.mysociety.org/
Other
24 stars 18 forks source link

Refresh or rebind multiselect #19

Open chandang-Chetu opened 4 years ago

chandang-Chetu commented 4 years ago

Hi,

I need to refresh ,rebuild or destroy previous and bind new multiselect.

I used $("#MymultiselectId").multiSelect('destroy') , $("#MymultiselectId").multiSelect('refresh'), and $("#MymultiselectId").multiSelect('rebuild'). But can not refresh or rebind the multiselect on dropdown rebind.

Please let us know what should i use.

Thanks.

hedka77 commented 3 years ago

Are you still looking for an answer?? I had the same problem and my dirty solution was to put my select within a div, and every time I need to refresh the multiSelect I empty the div, insert the html with the same select and then use .multiSelect again

gadeutham2000 commented 2 years ago

Thanks for your answer. It was really helpful. We were scratching our heads from a long time.

gregfr commented 2 years ago

Does anyone has a cleaner solution?

DreadPirateFlint commented 2 months ago

The following worked for me, mid-2024.

<div id="projects_dropdown">
<select size="5" name="projectid" id="project_select" class="selectpicker" multiple>
  <option value="value1">Value 1</option>
  <option value="hello there">hello there</option></select>
</div>

# append a new element to the original, hidden select list
$('#project_select').append($('<option/>', { value: 'hi', text : 'hi' }));

# remove the multiselect from the DOM
$('#projects_dropdown .multi-select-container').remove();

# re-initialize it.
$('#projectid').data("plugin_multiSelect").init();