javascriptjquerytwitter-bootstrapbootstrap-multiselect

How to deselect all selected values from bootstrap-multiselect with reset button?


I am having issues when trying to select the element which contains all the selected values.

For example: if you select by id such as 

$('#campaign-select').multiselect('refresh'),

it is not doing anything. Why is that?

Please see jsFiddle

FIXED IT!

$('#filter-reset-btn').on('click', function () {

               $('#campaigns-select').multiselect('rebuild');
               /* resetting the select element to refresh*/
               $('#campaigns-select,#sites-select,#mdmadservers-select,#ratetypes-select option:selected').each(function () {

                   $(this).prop('selected', false);

               })

               $('#campaigns-select,#sites-select,#mdmadservers-select,#ratetypes-select').val([]).multiselect('refresh')



           });

Here is updated to jsFiddle


Solution

  • You need to set the value to an empty array before refreshing the multi select. Also, note that you are missing an "s" in "campaign" inside you selector.

    Use this: $('#campaigns-select').val([]).multiselect('refresh')