Chosen is a jQuery plugin that makes long, unwieldy select boxes much more user-friendly.
Turns This
Into This
Turns This
Into This
Single Select with Groups
Multiple Select with Groups
Chosen automatically highlights selected options and removes disabled options.
Single Select
Multiple Select
The disable_search_threshold option can be specified to hide the search input on single selects if there are fewer than (n) options.
$(".chosen-select").chosen({disable_search_threshold: 10});
Chosen automatically sets the default field text ("Choose a country...") by reading the select element's data-placeholder value. If no data-placeholder value is present, it will default to "Select an Option" or "Select Some Options" depending on whether the select is single or multiple. You can change these elements in the plugin js file as you see fit.
<select data-placeholder="Choose a country..." style="width:350px;" multiple class="chosen-select">
Note: on single selects, the first element is assumed to be selected by the driver. To take advantage of the default text support, you will need to include a blank option as the first element of your select list.
Setting the "No results" search text is as easy as passing an option when you create Chosen:
$(".chosen-select").chosen({no_results_text: "Oops, nothing found!"});
Single Select
Multiple Select
You can easily limit how many options the user can select:
$(".chosen-select").chosen({max_selected_options: 5});
If you try to select another option with limit reached chosen:maxselected
event is triggered:
$(".chosen-select").bind("chosen:maxselected", function () { ... });
When a single select box isn't a required field, you can set allow_single_deselect: true
and Chosen will add a UI element for option deselection. This will only work if the first option has blank text.