A jQuery plugin for Bootstrap 4 that converts <select> and <select multiselect> elements to dropdowns. Uses fuse.js for fuzzy search and Bootstrap's dropdown plugin.

Defaults

Plugin defaults:

$(document).ready(function(){
  $("#multiselect").selectDropdown({
    // Behaviour
    maxListLength: 4,
    hideSelect: true,
    search: true,
    maxHeight: "300px",
    keyboard: true,
    badges: false,
    badgesDismissable: true,
    // Text
    textNoneSelected: "None selected",
    textMultipleSelected: "%count_selected% selected",
    textNoResults: "No results",
    // Buttons
    btnClear: true,
    btnDeselectAll: true,
    btnSelectAll: true,
    // HTML
    htmlBtnClear: "Clear search",
    htmlBtnDeselectAll: "Deselect all",
    htmlBtnSelectAll: "Select all",
    htmlBtnBadgeRemove: "[deselect]",
    // Classes
    classBtnSelect : "btn btn-primary",
    classBtnClear : "btn btn-outline-secondary",
    classBtnDeselectAll : "btn btn-outline-secondary",
    classBtnSelectAll : "btn btn-outline-secondary",
    classBadge: "badge badge-dark mr-1",
    classBadgeContainer : "mt-2 mb-3"
  })
});

maxListLength

Default
4

Limit the number of options to list as comma separated values within the dropdown button elements. If the number of selected options exceeds this limit, the value of textMultipleSelected will be displayed.

Set as 0 to disable.

hideSelect

Default
true

Hide the <select> element. This is expected. However, you may wish to unhide the <select> element for testing.

search

Default
true

Convert the dropdown button to an input-group, with a search form control and a clear search button.

maxHeight

Default
"300px"

Set a max height on the dropdown, enabling it to be scrollable. This can be disabled by setting the option to false.

keyboard

Default
true

Enable keyboard navigation. While the search control is focused, cursor keys/the enter key can be used to select options.

badges

Default
false
Conditions
Multiselect elements only.

Display badges below the element that represent selected options.

badgesDismissable

Default
true
Conditions
badges is true.
Multiselect elements only.

Badges can be dismissed to deselect options.

textNoneSelected

Default
"None selected"
Conditions
Multiselect elements only.

Dropdown button text when no items are selected.

textMultipleSelected

Default
"%count_selected% selected"
Conditions
Multiselect elements only.

Dropdown button text when multiple items are selected and maxListLength is exceeded.

The %count_selected% keyword is available to display the number of selected items.

textNoResults

Default
"No results"
Conditions
search is true.

This text appears when a search yields no results.

btnClear

Default
true
Conditions
search is true.

Include a clear search button in the input group.

btnDeselectAll

Default
true
Conditions
Multiselect elements only.

Include a deselect all button in the input group.

btnSelectAll

Default
true
Conditions
Multiselect elements only.

Include a select all button in the input group.

Include your own text/HTML values for:

  • The clear button.
  • The deselect all button.
  • The select all button.
  • The dismiss/deselect link within badges.

The example below use SVG sprite icons from Ionicons sprite by rastasheep who created sprites from ionicons, the premium icon font for Ionic Framework.

<div class="form-group">
  <label for="demo_options_html">Select one or more of your favourite foods</label>
  <select id="demo_overview_example" class="form-control" multiple>
    <!-- options -->
  </select>
</div>

<script>
  $(document).ready(function(){
    $("select#demo_options_html").selectDropdown({
      'badges': true,
      'htmlBtnClear': '<svg class="ion"><use xlink:href="#ion-close"></use></svg>',
      'htmlBtnDeselectAll': '<svg class="ion"><use xlink:href="#ion-close-circled"></use></svg>',
      'htmlBtnSelectAll': '<svg class="ion"><use xlink:href="#ion-checkmark-circled"></use></svg>',
      'htmlBtnBadgeRemove': '<svg class="ion"><use xlink:href="#ion-close"></use></svg>'
    });
  });
</script>

htmlBtnClear

Default
"Clear search"
Conditions
search is true.
btnClear is true.
Multiselect elements only.

htmlBtnDeselectAll

Default
"Deselect all"
Conditions
search is true.
btnDeselectAll is true.
Multiselect elements only.

htmlBtnSelectAll

Default
"Select all"
Conditions
search is true.
btnSelectAll is true.

htmlBtnBadgeRemove

Default
"[deselect]"
Conditions
badges is true.
Multiselect elements only.

classBtnSelect

Default
"btn btn-primary"

The class applied to the dropdown button.

classBtnClear

Default
"btn btn-outline-secondary"
Conditions
search is true.

The class applied to the clear button.

classBtnDeselectAll

Default
"btn btn-outline-secondary"
Conditions
Multiselect elements only.

The class applied to the deselect all button.

classBtnSelectAll

Default
"btn btn-outline-secondary"
Conditions
Multiselect elements only.

The class applied to the select all button.

classBadge

Default
"badge badge-dark mr-1"
Conditions
badges is true.
Multiselect elements only.

The class applied to badges.

classBadgeContainer

Default
"mt-2 mb-3"
Conditions
badges is true.
Multiselect elements only.

The class applied to the badge container.