Boostrap multiselect select all by default

I am using bootstrap-multiselect (v0.9.8) with the option

includeSelectAllOption: true 

Is it possible to select all that will be checked by default when the page loads?

THX

+6
source share
2 answers

The following is taken from http://davidstutz.imtqy.com/bootstrap-multiselect/ : I am currently using this solution with bootstrap 3.3.1 and bootstrap-multiselect v0.9.8 Remember to add a false parameter to the "selectAll" function, so as this will allow you to select all the parameters without first opening the drop-down list.

HTML example:

 <select class="multiselect" id="my-multi-select" name="options[]" multiple="multiple"> <option>1</option> <option>2</option> </select> 

Javascript example:

 $(function() { $('#my-multi-select').multiselect({ includeSelectAllOption: true }); $("#my-multi-select").multiselect('selectAll', false); $("#my-multi-select").multiselect('updateButtonText'); }); 
+16
source

Using bootstrap-select V.1.12.4, the solution is simpler:

HTML example:

 <select class="selectpicker" id="my-multi-select" name="options[]" multiple> <option>1</option> <option>2</option> </select> 

Javascript example:

 $(function() { $('#my-multi-select').selectpicker({ }); $("#my-multi-select").selectpicker('selectAll'); }); 
0
source

Source: https://habr.com/ru/post/977120/


All Articles