demo
demo

Reputation: 6245

DeselectAll doesn't work for Bootstrap-select

Here is example what i try, but didn't work.

JsFiddle

What i expect : on button click all options will be unselected.

I try with "refresh" and "render" but also didn't help.

 <select class="selectpicker" multiple title="Not changable text" data-count-selected-text="Not changable text">
         <option>Mustard</option>
         <option>Ketchup</option>
         <option>Relish</option>
 </select>

<button id="f1">ggg</button>

$('#f1').click(function(){
   $('.selectpicker').selectpicker('deselectAll');
});

UPDATE : code doesn't work if select is closed. In case it's open - all is good

Upvotes: 7

Views: 13314

Answers (5)

RBILLC
RBILLC

Reputation: 190

I was able to reset my non-multi selectpicker to the noneSelectedText with the following. It even works if you change the noneSelectedText.

$('.selectpicker').selectpicker('val', 'Nothing Selected').selectpicker("refresh");

Upvotes: 0

sealabr
sealabr

Reputation: 1672

This worked for me!

$('.selectpicker option:selected').val('');
$('.selectpicker').selectpicker('deselectAll');

Upvotes: 2

Mohd Naved
Mohd Naved

Reputation: 458

In addition to Artur Filipiak answer,

If it does not work for you, add this :

$('.selectpicker').selectpicker('refresh');

after you add :

$('.selectpicker').selectpicker('val', '');

it should look something like this :

$('.selectpicker').selectpicker('val', '');
$('.selectpicker').selectpicker('refresh');

Upvotes: 1

Artur Filipiak
Artur Filipiak

Reputation: 9157

EDIT

There was a bug with deselectAll and is now fixed


You can empty selection using val :

$('#f1').click(function(){
    $('.selectpicker').selectpicker('val', '');
});

DeselectAll should theoretically do the job, but for some reason it doesn't. (it does now)

DEMO

Upvotes: 18

UWU_SANDUN
UWU_SANDUN

Reputation: 1193

I got solution from following code.Try it

$("#listID").val('').trigger('change');

Upvotes: 2

Related Questions