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
To programmatically update a select with JavaScript, first manipulate the select, then use the refresh method to update the UI to match the new state. This is necessary when removing or adding options, or when disabling/enabling a select via JavaScript.
.selectpicker('destroy') To programmatically destroy the bootstrap-select, use the destroy method. $('. selectpicker'). selectpicker('destroy');
Basic Picker It will load first option as selected one, therefore if you want to have placeholder use first option as placeholder. Also Picker support hidden attribute, therefore if you don't want to have placeholder in list of options, use it with your placeholder option.
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.
DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With