coool
coool

Reputation: 8297

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.

Upvotes: 7

Views: 25011

Answers (2)

Pramod
Pramod

Reputation: 513

$("#multiselectelement").multiselect("uncheckAll");

Upvotes: 10

dku.rajkumar
dku.rajkumar

Reputation: 18568

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/

Upvotes: 14

Related Questions