Home > Enterprise >  selectize.js select dropdown show by default opened
selectize.js select dropdown show by default opened

Time:10-09

I'm using selectize.js for my search form and want to show select list opened by default.

<select id="select-state" name="state[]" multiple class="demo-default" placeholder="Select Models">
 <option value="">Select Models</option>
 <option value="Tanzania">Tanzania</option>
 <option value="Kenya">Kenya</option>
 <option value="Uganda">Uganda</option>
 <option value="Asia">Asia</option>
 <option value="Malaysia">Malaysia</option>
 <option value="Japan">Japan</option>
</select>
<script>
$('#select-state').selectize({
    maxItems: 5
});
</script>

I have tried different methods but none of them are working. By jQuery

$('#select-state').show().focus().click();

By CSS

<style>.selectize-dropdown{ display:block!important; visibility:visible!important;}</style>

CodePudding user response:

Try this :

var select = $('#select-state').selectize({
  maxItems: 5
});
var selectize = select[0].selectize;
selectize.open();
<link href="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/css/selectize.css" rel="stylesheet"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/js/standalone/selectize.js"></script>

<select id="select-state" name="state[]" multiple class="demo-default" placeholder="Select Models">
  <option value="">Select Models</option>
  <option value="Tanzania">Tanzania</option>
  <option value="Kenya">Kenya</option>
  <option value="Uganda">Uganda</option>
  <option value="Asia">Asia</option>
  <option value="Malaysia">Malaysia</option>
  <option value="Japan">Japan</option>
</select>

  • Related