This time I will share jQuery Plugin and tutorial about Multiple Select With Filter And Checkboxes Using jQuery, hope it will help you in programming stack.
A jQuery plugin that converts a normal select box into a user-friendly filterable multi-select dropdown where your users are able to select one or more options by checking checkboxes.
Licensed under the LGPL-2.1 License.
More Features:
- A ROOT checkbox that allows you to select all options with a single click.
- Compatible with the latest Bootstrap 4.
- Allows to append more options to the select dropdown via JavaScript.
- Keyboard accessibility.
- Especially suitable for tags input that enables the user to select tags from a predefined list.
How to use it:
1. Load jQuery library (required) and Bootstrap’s stylesheet (optional but recommended) in the document.
1 |
< link rel = "stylesheet" href = "filter_multi_select.css" /> |
2 |
< script src = "filter-multi-select-bundle.min.js" ></ script > |
2. Load the filter-multi-select plugin’s JavaScript and Stylesheet in the document.
1 |
< link rel = "stylesheet" href = "/path/to/cdn/bootstrap.min.css" /> |
2 |
< script src = "/path/to/cdn/jquery.slim.min.js" ></ script > |
3. Create a basic filterable multielect dropdown by simply attaching the function filterMultiSelect
to the existing select box with the multiple
attribute:
1 |
< select multiple name = "language" id = "languages" > |
2 |
< option value = "js" >JavaScript</ option > |
3 |
< option value = "html" >HTML</ option > |
4 |
< option value = "css" >CSS</ option > |
5 |
... more options here ... |
1 |
const languages = $( '#languages' ).filterMultiSelect(); |
4. You can also add options to the multielect dropdown via JavaScript.
- label: Lable text
- value: Option value
- selected: Is selected?
- disabled: Is disabled?
1 |
const languages = $( '#languages' ).filterMultiSelect({ |
5. Available options to customize the multielect dropdown.
01 |
const languages = $( '#languages' ).filterMultiSelect({ |
04 |
placeholderText: "nothing selected" |
10 |
selectAllText: "Select All" , |
16 |
allowEnablingAndDisabling: true |
6. API methods.
02 |
languages.hasOption(value); |
05 |
languages.selectOption(value:string); |
06 |
languages.deselectOption(value:string); |
09 |
languages.isOptionSelected(value:string); |
12 |
languages.selectAll(); |
13 |
languages.deselectAll(); |
16 |
languages.enableOption(value:string); |
17 |
languages.disableOption(value:string); |
20 |
languages.isOptionDisabled(value:string); |
27 |
languages.getSelectedOptionsAsJson(includeDisabled= true ); |
Changelog:
v1.1.0 (2021-03-11)
- Append the class filter-multi-select to select elements and have the plugin be applied automatically.
- Or define your own selector in $.fn.filterMultiSelect.selector.
- Access all element groups applied by the plugin in $.fn.filterMultiSelect.applied.
About Author:
Author: Andrew
Website: https://github.com/andreww1011/filter-multi-select