Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to unselect all options in multiselect widget

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

This doesn't work. When the select options are selected manually, check for no of unchecked options in select it gives me 1 (at the click of last option) the first time. so I checked if $this.children("option").not('[selected]').length is 1 and ui.checked and calling the uncheckAll but after that it is behaving properly the code if $this.children("option").not('[selected]').length gives me 0 when selecting the final one.

I am wondering what is happening.

like image 431
coool Avatar asked Feb 13 '12 15:02

coool


1 Answers

well so here is the solution what you want... check the documentation , there is method getChecked to get selected options. yours is not working because the pluging reformat the select elements.

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

fiddle example : http://jsfiddle.net/fG6PT/11/

like image 192
dku.rajkumar Avatar answered Sep 30 '22 14:09

dku.rajkumar