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.
Plugin defaults:
$(document).ready(function(){
$("#multiselect").selectDropdown({
// Behaviour
maxListLength: 4,
hideSelect: true,
search: true,
maxHeight: "300px",
keyboard: true,
badges: false,
badgesDismissable: true,
tooltips: false,
// 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"
})
});
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.
true
Hide the <select> element. This is expected. However, you may wish to unhide the <select> element for testing.
true
Convert the dropdown button to an input-group
, with a search form control and a clear search button.
"300px"
Set a max height on the dropdown, enabling it to be scrollable. This can be disabled by setting the option to false
.
true
Enable keyboard navigation. While the search control is focused, cursor keys/the enter key can be used to select options.
false
Display badges below the element that represent selected options.
true
badges
is true
.Badges can be dismissed to deselect options.
false
Display tooltips on hover over input group buttons. Useful when using icons as the button text.
"None selected"
Dropdown button text when no items are selected.
"%count_selected% selected"
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.
"No results"
search
is true
.
This text appears when a search yields no results.
true
search
is true
.
Include a clear search button in the input group.
true
Include a deselect all button in the input group.
true
Include a select all button in the input group.
Include your own text/HTML values for:
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>
"Clear search"
search
is true
.btnClear
is true
."Deselect all"
search
is true
.btnDeselectAll
is true
."Select all"
search
is true
.btnSelectAll
is true
."[deselect]"
badges
is true
."btn btn-primary"
The class applied to the dropdown button.
"btn btn-outline-secondary"
search
is true
.
The class applied to the clear button.
"btn btn-outline-secondary"
The class applied to the deselect all button.
"btn btn-outline-secondary"
The class applied to the select all button.
"badge badge-dark mr-1"
badges
is true
.The class applied to badges.
"mt-2 mb-3"
badges
is true
.The class applied to the badge container.