Reputation: 6245
Here is example what i try, but didn't work.
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
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
Reputation: 1672
This worked for me!
$('.selectpicker option:selected').val('');
$('.selectpicker').selectpicker('deselectAll');
Upvotes: 2
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
Reputation: 9157
There was a bug with deselectAll
and is now fixed
You can empty selection using val
:
$('#f1').click(function(){
$('.selectpicker').selectpicker('val', '');
});
(it does now)DeselectAll
should theoretically do the job, but for some reason it doesn't.
Upvotes: 18
Reputation: 1193
I got solution from following code.Try it
$("#listID").val('').trigger('change');
Upvotes: 2