Bishwarup Das Bishwarup Das - 2 months ago 32
jQuery Question

Bootstrap Select-Picker prevent close

Hey Guys I am working with Bootstrap Select-picker. I want to open the drop list by default and not to close the select-picker on focus out.

Code:

<select class="selectpicker" multiple data-live-search="true" data-actions-box="true">
<optgroup label="filter1">
<option>option1</option>
<option>option2</option>
<option>option3</option>
<option>option4</option>
</optgroup>
<optgroup label="filter2">
<option>option1</option>
<option>option2</option>
<option>option3</option>
<option>option4</option>
</optgroup>
<optgroup label="filter3">
<option>option1</option>
<option>option2</option>
<option>option3</option>
<option>option4</option>
</optgroup>
</select>
<script type="text/javascript">
$('.selectpicker').selectpicker();
</script>




Is this possible??

Answer

You can add some jQuery to have it auto open, and re-open when anywhere in the document is clicked (causing it normally to lose focus and close)..

//auto open
$('[data-id=mySel]').trigger('click');

//stay open
$(document).on("click", function () {
   $('[data-id=mySel]').trigger('click');
});

Demo: http://www.bootply.com/77umTeRI6n

Comments