Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap multiselect - De-select / Uncheck all options in a single click

I'm using Bootstrap multiselect and I would like to add an option to uncheck all selected options. Please provide me with a solution for the same. Thanks for any help :)

like image 619
2dar Avatar asked Mar 27 '14 11:03

2dar


1 Answers

You can use .multiselect('refresh') method as mentioned in the bootstrap-multiselect documentation here.

So, add an HTML button / icon next to the multi-select select list and then use the below code:

$("#reset_client").click(function(){
  $('option', $('#select_client')).each(function(element) {
    $(this).removeAttr('selected').prop('selected', false);
  });
  $("#select_client").multiselect('refresh');
});
<select name="clients[]" multiple="multiple" id="select_client" style="display: none;">
    <option value="multiselect-all"> Select all</option>
    <option value="1">Client 1</option>
    <option value="2">Client 2</option>
    <option value="3">Client 3</option>
    <option selected="selected" value="4">Client 4</option>
    <option selected="selected" value="5">Client 5</option>
    <option value="6">Client 6</option>
    <option selected="selected" value="7">Client 7</option>
    <option value="8">Client 8</option>
</select>

<input type="button" value="Reset" name="reset_clients" id="reset_client" class="reset_button" title="Clear Selection">
like image 124
Rajesh Omanakuttan Avatar answered Sep 20 '22 13:09

Rajesh Omanakuttan