Chosen (v2.2.0)
Chosen has a number of options and attributes that allow you to have full control of your select boxes.
Options
The following options are available to pass into Chosen on instantiation.
Example:
$(".my_select_box").chosen({
disable_search_threshold: 10,
no_results_text: "Oops, nothing found!",
width: "95%"
});
Option | Default | Description |
---|---|---|
allow_single_deselect | false | When set to true on a single select, Chosen adds a UI element which selects the first element (if it is blank). |
disable_search | false | When set to true , Chosen will not display the search field (single selects only). |
disable_search_threshold | 0 | Hide the search input on single selects if there are n or fewer options. |
enable_split_word_search | true | By default, searching will match on any word within an option tag. Set this option to false if you want to only match on the entire text of an option tag. |
inherit_select_classes | false | When set to true , Chosen will grab any classes on the original select field and add them to Chosen’s container div. |
inherit_option_classes | false | When set to true , Chosen will grab any classes on the original option tags and add them to Chosen’s container li. |
max_selected_options | Infinity | Limits how many options the user can select. When the limit is reached, the chosen:maxselected event is triggered. |
no_results_text | "No results for:" | The text to be displayed when no matching results are found. The current search is shown at the end of the text (e.g., No results for: "Bad Search"). |
placeholder_text_multiple | "Select Some Options" | The text to be displayed as a placeholder when no options are selected for a multiple select. |
placeholder_text_single | "Select an Option" | The text to be displayed as a placeholder when no options are selected for a single select. |
search_contains | false | By default, Chosen’s search matches starting at the beginning of a word. Setting this option to true allows matches starting from anywhere within a word. This is especially useful for options that include a lot of special characters or phrases in ()s and []s. |
search_in_values | false | By default, Chosen’s search matches in content of HTML<option> element. Setting this option to true allows matches in value attribute of the <option> element. |
group_search | true | By default, Chosen will search group labels as well as options, and filter to show all options below matching groups. Set this to false to search only in the options. |
single_backstroke_delete | true | By default, pressing delete/backspace on multiple selects will remove a selected choice. When false , pressing delete/backspace will highlight the last choice, and a second press deselects it. |
width | Original select width. | The width of the Chosen select box. By default, Chosen attempts to match the width of the select box you are replacing. If your select is hidden when Chosen is instantiated, you must specify a width or the select will show up with a width of 0. |
display_disabled_options | true | By default, Chosen includes disabled options in search results with a special styling. Setting this option to false will hide disabled results and exclude them from searches. |
display_selected_options | true |
By default, Chosen includes selected options in search results with a special styling. Setting this option to false will hide selected results and exclude them from searches. Note: this is for multiple selects only. In single selects, the selected result will always be displayed. |
include_group_label_in_selected | false |
By default, Chosen only shows the text of a selected option. Setting this option to |
max_shown_results | Infinity |
Only show the first (n) matching options in the results. This can be used to increase performance for selects with very many options. |
case_sensitive_search | false |
By default, Chosen's search is case-insensitive. Setting this option to |
hide_results_on_select | true |
By default, Chosen's results are hidden after a option is selected. Setting this option to |
rtl | false |
Chosen supports right-to-left text in select boxes. Set this option to Note: the |
Attributes
Certain attributes placed on the select tag or its options can be used to configure Chosen.
Example:
<select class="my_select_box" data-placeholder="Select Your Options">
<option value="1">Option 1</option>
<option value="2" selected>Option 2</option>
<option value="3" disabled>Option 3</option>
<option value="4" hidden>Option 4</option>
</select>
Attribute | Description |
---|---|
data-placeholder |
The text to be displayed as a placeholder when no options are selected for a select. Defaults to "Select an Option" for single selects or "Select Some Options" for multiple selects. Note:This attribute overrides anything set in the |
multiple | The attribute multiple on your select box dictates whether Chosen will render a multiple or single select. |
selected, disabled, hidden | Chosen automatically highlights selected options, hides hidden options and disables disabled options. |
Classes
Classes placed on the select tag can be used to configure Chosen.
Example:
<select class="my_select_box chosen-rtl">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
Classname | Description |
---|---|
chosen-rtl |
Chosen supports right-to-left text in select boxes. Add the class Note: The Note: This is deprecated in favor of using the |
Triggered Events
Chosen triggers a number of standard and custom events on the original select field.
Example:
$('.my_select_box').on('change', function(evt, params) {
do_something(evt, params);
});
Event | Description |
---|---|
change |
Chosen triggers the standard DOM event whenever a selection is made (it also sends a Note: The selected and deselected parameters are not available for Prototype. |
chosen:ready | Triggered after Chosen has been fully instantiated. |
chosen:maxselected | Triggered if max_selected_options is set and that total is broken. |
chosen:search_updated | Triggered when Chosen’s search results are updated after typing search term.
The event includes a corresponding search_term parameter. |
chosen:showing_dropdown | Triggered when Chosen’s dropdown is opened. |
chosen:hiding_dropdown | Triggered when Chosen’s dropdown is closed. |
chosen:search | Triggered when Chosen has performed search. |
chosen:no_results | Triggered when a search returns no matching results. |
Note: all custom Chosen events (those that begin with chosen:
) also include the chosen
object as a parameter.
Triggerable Events
You can trigger several events on the original select field to invoke a behavior in Chosen.
Example:
// tell Chosen that a select has changed
$('.my_select_box').trigger('chosen:updated');
Event | Description |
---|---|
chosen:updated | This event should be triggered whenever Chosen’s underlying select element changes (such as a change in selected options). |
chosen:activate | This is the equivalant of focusing a standard HTML select field. When activated, Chosen will capture keypress events as if you had clicked the field directly. |
chosen:open | This event activates Chosen and also displays the search results. |
chosen:close | This event deactivates Chosen and hides the search results. |
- Concept and development by Patrick Filler for Harvest.
- Design and CSS by Matthew Lettini.
- 1.8.x and earlier maintained by @pfiller, @kenearley, @stof, @koenpunt, and @tjschuck.
- 2.0.x and later maintained by @jjj.
- Chosen includes contributions by many fine folks.