How to deselect all options in multi selector widgets

I am using jquery multiselect widget. I would like to uncheck all the checkboxes if all of them were checked manually. I have sample code in JSFiddle -> Code

This does not work. When the selection options are manually selected, select the No check box for unverified options on the selection, which gives me 1 (by clicking the last option) for the first time. so I checked if $this.children("option").not('[selected]').length is 1 and ui.checked and calls uncheckAll but after that it behaves correctly if $this.children("option").not('[selected]').length gives me 0 when choosing the final one.

I wonder what is going on.

+6
source share
2 answers

So, here is the solution you want ... check the documentation , there is a getChecked method to get selected options . yours does not work because the plugin reformatts the selected elements.

 $('.multi').multiselect({ click: function(e, ui){ if($(this).multiselect("getChecked").length == $('select.multi > option').length){ $(this).multiselect("uncheckAll"); } } }); 

Sample script: http://jsfiddle.net/fG6PT/11/

+12
source
 $("#multiselectelement").multiselect("uncheckAll"); 
+9
source

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


All Articles