Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap-Multiselect issue with form reset and checkboxes repopulating

I'm using bootstrap-multiselect for a dropdown in my application. Everything works fine except for my form reset, when I want it to revert back to the originally selected values. It's displaying the selected values as expected in the menu when it's closed (i.e. creating a list with multiple selections), but when I open the menu the checkboxes for the selected items aren't checked.

I've tried the following to no avail:

$("#MyMenu").multiselect('refresh');
$("#MyMenu").multiselect('rebuild');
$("#MyMenu").multiselect('destroy');

followed by

$("#MyMenu").multiselect();

Any help is appreciated!

like image 735
jenni-mm2 Avatar asked Sep 23 '14 19:09

jenni-mm2


2 Answers

For me it works simply with:

$('#id').multiselect('refresh');

However, it must be noted that the reset event fires before the form inputs are actually reset. Practically speaking, this means that the following won't work:

$('#formID').on('reset', function(){
    $('#id').multiselect('refresh');
});

while wrapping the call inside of an instantaneous setTimeout will work!

$('#formID').on('reset', function(){
    setTimeout(function(){
        $('#id').multiselect('refresh');
    });
});
like image 110
Dre Avatar answered Sep 19 '22 23:09

Dre


today i faced same issue...i did

$("option:selected").removeAttr("selected");
$("#MyMenu").multiselect('refresh');

It worked for me...

like image 45
Bhupendra Pandey Avatar answered Sep 20 '22 23:09

Bhupendra Pandey