GitHub Address: https://harvesthq.github.io/chosen/#change-update-events
Using Chosen is easy as can. Download the plugin and copy the chosen files to your app. Activate the plugin on the select boxes of your choice: $ (". Cho Sen-select "). Chosen () Disco. Chosen Options Property settings
GitHub Address: https://harvesthq.github.io/chosen/options.html
Options
The following options is 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 of 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 won't display the search field (single selects only). |
Disable_search_threshold |
0 |
Hide the search input on single selects if there is n or fewer options. |
Enable_split_word_search |
True |
By default, searching would match on any word within an option tag. Set This option Tofalse if you want to match on the entire text of a option tag. |
Inherit_select_classes |
False |
When set to true, Chosen'll grab any classes on the original Select field and add them to Chosen ' s container div. |
Max_selected_options |
Infinity |
Limits How many options the user can select. When the limit was reached, the chosen:maxselected event is triggered. |
No_results_text |
"No results Match" |
The text to is displayed when no matching results is found. The current search was shown at the end of the text (e.g., No results Match "bad search"). |
Placeholder_text_multiple |
"Select Some Options" |
The text to is displayed as a placeholder when no options is selected for a multiple select. |
Placeholder_text_single |
"Select an Option" |
The text to is displayed as a placeholder when no options is selected for a single select. |
Search_contains |
False |
By default, Chosen's search matches starting at the beginning of a word. Setting This option totrue allows matches starting from anywhere within a word. This is especially useful for options which include a lot of special characters or phrases in () s and []s. |
Single_backstroke_delete |
True |
By default, the pressing Delete/backspace on multiple selects would remove a selected choice. Whenfalse, pressing Delete/backspace would 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 is replacing. If Your Select is hidden when Chosen are instantiated, you must specify a width or the select would show up with a width of 0. |
Display_disabled_options |
True |
By default, Chosen includes disabled options on search results with a special styling. Setting this option to false would hide disabled results and exclude them from searches. |
Display_selected_options |
True |
By default, Chosen includes selected options on search results with a special styling. Setting this option to false would hide selected results and exclude them from searches. Note: This was for multiple selects only. In a single selects, the selected result would always be displayed. |
include_group_label_in_selected |
False |
By default, Chosen only shows the text of a selected option. Setting This option totrue would show the text and group (if any) of the selected option. |
Max_shown_results |
Infinity |
Only show the first (n) matching options in the results. This can is 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 true makes the search case-sensitive. |
Attributes
Certain attributes placed on the SELECT tag or its options can is 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>
</select>
Attribute |
Description |
Data-placeholder |
The text to is displayed as a placeholder when no options is 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 Placeholder_text_multiple or Placeholder_text_single options. |
Multiple |
The attribute multiple on your select box dictates whether Chosen would render a multiple or single select. |
selected, disabled |
Chosen automatically highlights selected options and disables disabled options. |
Classes
Classes placed on the select tag can is 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 Chosen-rtl to your select tag to support right-to-left text options. Note: The Chosen-rtl class would pass through to the chosen select even when theinherit_select_classes option is set Tofalse. |
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 are made (it also sends aselected or deselected parameter that Tells you which option is changed). Note: in the order-to-use change in the Prototype-version, you are to include Theevent.simulate class. The selected and deselected parameters is not available for Prototype. |
Chosen:ready |
Triggered after Chosen have been fully instantiated. |
chosen:maxselected |
The triggered if max_selected_options is set and the is broken. |
Chosen:showing_dropdown |
triggered when Chosen ' s dropdown is opened. |
Chosen:hiding_dropdown |
triggered when Chosen ' s dropdown is closed. |
Chosen:no_results |
Triggered when a search returns no matching results. |
Note: All custom Chosen events (those this 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, a SELECT has changed
$ ('. My_select_box '). Trigger (' chosen:updated ');
Event |
Description |
chosen:updated |
This event should is triggered whenever Chosen ' s underlying select element changes (such as a change in selected options). |
Chosen:activate |
The equivalant of focusing a standard HTML select field. When activated, Chosen would capure 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. |