Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 296
demo Avatar asked Feb 05 '15 16:02

demo


People also ask

How do I append to bootstrap select?

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.

How to destroy selectpicker?

.selectpicker('destroy') To programmatically destroy the bootstrap-select, use the destroy method. $('. selectpicker'). selectpicker('destroy');

What does selectpicker do?

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.


1 Answers

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

like image 127
Artur Filipiak Avatar answered Oct 12 '22 05:10

Artur Filipiak