-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
options.html
311 lines (289 loc) · 13.8 KB
/
options.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Chosen: A jQuery Plugin by Harvest to Tame Unwieldy Select Boxes</title>
<link rel="stylesheet" href="docsupport/style.css">
<link rel="stylesheet" href="docsupport/prism.css">
<link rel="stylesheet" href="chosen.css">
<style type="text/css" media="all">
/* fix rtl for demo */
.chosen-rtl .chosen-drop { left: -9000px; }
</style>
</head>
<body>
<div id="container">
<div id="content">
<header>
<h1>Chosen <small>(<span id="latest-version">v1.8.7</span>)</small></h1>
</header>
<p>Chosen has a number of options and attributes that allow you to have full control of your select boxes.</p>
<h2><a name="options" class="anchor" href="#options">Options</a></h2>
<p>The following options are available to pass into Chosen on instantiation.</p>
<h3>Example:</h3>
<pre>
<code class="language-javascript">$(".my_select_box").chosen({
disable_search_threshold: 10,
no_results_text: "Oops, nothing found!",
width: "95%"
});</code>
</pre>
<table class="docs-table">
<tr>
<th>Option</th><th>Default</th><th>Description</th>
</tr>
<tr>
<td>allow_single_deselect</td>
<td>false</td>
<td>When set to <code class="language-javascript">true</code> on a single select, Chosen adds a UI element which selects the first element (if it is blank).</td>
</tr>
<tr>
<td>disable_search</td>
<td>false</td>
<td>When set to <code class="language-javascript">true</code>, Chosen will not display the search field (single selects only).</td>
</tr>
<tr>
<td>disable_search_threshold</td>
<td>0</td>
<td>Hide the search input on single selects if there are <i>n</i> or fewer options.</td>
</tr>
<tr>
<td>enable_split_word_search</td>
<td>true</td>
<td>By default, searching will match on any word within an option tag. Set this option to <code class="language-javascript">false</code> if you want to only match on the entire text of an option tag.</td>
</tr>
<tr>
<td>inherit_select_classes</td>
<td>false</td>
<td>When set to <code class="language-javascript">true</code>, Chosen will grab any classes on the original select field and add them to Chosen’s container div.</td>
</tr>
<tr>
<td>max_selected_options</td>
<td>Infinity</td>
<td>Limits how many options the user can select. When the limit is reached, the <code class="language-javascript">chosen:maxselected</code> event is triggered.</td>
</tr>
<tr>
<td>no_results_text</td>
<td>"No results match"</td>
<td>The text to be displayed when no matching results are found. The current search is shown at the end of the text (<i>e.g.</i>,
No results match "Bad Search").</td>
</tr>
<tr>
<td>placeholder_text_multiple</td>
<td>"Select Some Options"</td>
<td>The text to be displayed as a placeholder when no options are selected for a multiple select.</td>
</tr>
<tr>
<td>placeholder_text_single</td>
<td>"Select an Option"</td>
<td>The text to be displayed as a placeholder when no options are selected for a single select.</td>
</tr>
<tr>
<td>search_contains</td>
<td>false</td>
<td>By default, Chosen’s search matches starting at the beginning of a word. Setting this option to <code class="language-javascript">true</code> 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.</td>
</tr>
<tr>
<td>group_search</td>
<td>true</td>
<td>By default, Chosen will search group labels as well as options, and filter to show all options below matching groups. Set this to <code class="language-javascript">false</code> to search only in the options.</td>
</tr>
<tr>
<td>single_backstroke_delete</td>
<td>true</td>
<td>By default, pressing delete/backspace on multiple selects will remove a selected choice. When <code class="language-javascript">false</code>, pressing delete/backspace will highlight the last choice, and a second press deselects it.</td>
</tr>
<tr>
<td>width</td>
<td>Original select width.</td>
<td>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.</td>
</tr>
<tr>
<td>display_disabled_options</td>
<td>true</td>
<td>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.</td>
</tr>
<tr>
<td>display_selected_options</td>
<td>true</td>
<td>
<p>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.</p>
<p><strong>Note:</strong> this is for multiple selects only. In single selects, the selected result will always be displayed.</p>
</td>
</tr>
<tr>
<td>include_group_label_in_selected</td>
<td>false</td>
<td>
<p>By default, Chosen only shows the text of a selected option. Setting this option to <code class="language-javascript">true</code> will show the text and group (if any) of the selected option.</p>
</td>
</tr>
<tr>
<td>max_shown_results</td>
<td>Infinity</td>
<td>
<p>Only show the first (n) matching options in the results. This can be used to increase performance for selects with very many options.</p>
</td>
</tr>
<tr>
<td>case_sensitive_search</td>
<td>false</td>
<td>
<p>By default, Chosen's search is case-insensitive. Setting this option to <code class="language-javascript">true</code> makes the search case-sensitive.</p>
</td>
</tr>
<tr>
<td>hide_results_on_select</td>
<td>true</td>
<td>
<p>By default, Chosen's results are hidden after a option is selected. Setting this option to <code class="language-javascript">false</code> will keep the results open after selection. This only applies to multiple selects.</p>
</td>
</tr>
<tr>
<td>rtl</td>
<td>false</td>
<td>
<p>Chosen supports right-to-left text in select boxes. Set this option to <code class="language-javascript">true</code> to support right-to-left text options.</p>
<p><strong>Note:</strong> <a href="#classes">the <code class="language-javascript">chosen-rtl</code> class</a> on the select has precedence over this option. However, the classname approach is deprecated and will be removed in future versions of Chosen.</p>
</td>
</tr>
</table>
<h2><a name="attributes" class="anchor" href="#attributes">Attributes</a></h2>
<p>Certain attributes placed on the select tag or its options can be used to configure Chosen.</p>
<h3>Example:</h3>
<pre>
<code class="language-markup"><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></code>
</pre>
<table class="docs-table">
<tr>
<th>Attribute</th><th>Description</th>
</tr>
<tr>
<td>data-placeholder</td>
<td>
<p>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.</p>
<p><strong>Note:</strong>This attribute overrides anything set in the <code class="language-javascript">placeholder_text_multiple</code> or <code class="language-javascript">placeholder_text_single</code> options.</p>
</td>
</tr>
<tr>
<td>multiple</td>
<td>The attribute <code class="language-html">multiple</code> on your select box dictates whether Chosen will render a multiple or single select.</td>
</tr>
<tr>
<td>selected, disabled</td>
<td>Chosen automatically highlights selected options and disables disabled options.</td>
</tr>
</table>
<h2><a name="classes" class="anchor" href="#classes">Classes</a></h2>
<p>Classes placed on the select tag can be used to configure Chosen.</p>
<h3>Example:</h3>
<pre>
<code class="language-markup"><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></code>
</pre>
<table class="docs-table">
<tr>
<th>Classname</th>
<th>Description</th>
</tr>
<tr>
<td>chosen-rtl</td>
<td>
<p>Chosen supports right-to-left text in select boxes. Add the class <code class="language-html">chosen-rtl</code> to your select tag to support right-to-left text options.</p>
<p><strong>Note:</strong> The <code class="language-html">chosen-rtl</code> class will pass through to the Chosen select even when the <code class="language-javascript">inherit_select_classes</code> option is set to <code class="language-javascript">false</code>.</p>
<p><strong>Note:</strong> This is deprecated in favor of using the <code class="language-javascript">rtl: true</code> option (see the <a href="#options">Options section</a>).</p>
</td>
</tr>
</table>
<h2><a name="triggered-events" class="anchor" href="#triggered-events">Triggered Events</a></h2>
<p>Chosen triggers a number of standard and custom events on the original select field.</p>
<h3>Example:</h3>
<pre>
<code class="language-javascript">$('.my_select_box').on('change', function(evt, params) {
do_something(evt, params);
});</code>
</pre>
<table class="docs-table">
<tr>
<th>Event</th><th>Description</th>
</tr>
<tr>
<td>change</td>
<td>
<p>Chosen triggers the standard DOM event whenever a selection is made (it also sends a <code class="language-javascript">selected</code> or <code class="language-javascript">deselected</code> parameter that tells you which option was changed).</p>
<p><strong>Note:</strong> The selected and deselected parameters are not available for Prototype.</p>
</td>
</tr>
<tr>
<td>chosen:ready</td>
<td>Triggered after Chosen has been fully instantiated.</td>
</tr>
<tr>
<td>chosen:maxselected</td>
<td>Triggered if <code class="language-javascript">max_selected_options</code> is set and that total is broken.</td>
</tr>
<tr>
<td>chosen:showing_dropdown</td>
<td>Triggered when Chosen’s dropdown is opened.</td>
</tr>
<tr>
<td>chosen:hiding_dropdown</td>
<td>Triggered when Chosen’s dropdown is closed.</td>
</tr>
<tr>
<td>chosen:no_results</td>
<td>Triggered when a search returns no matching results.</td>
</tr>
</table>
<p>
<strong>Note:</strong> all custom Chosen events (those that begin with <code class="language-javascript">chosen:</code>) also include the <code class="language-javascript">chosen</code> object as a parameter.
</p>
<h2><a name="triggerable-events" class="anchor" href="#triggerable-events">Triggerable Events</a></h2>
<p>You can trigger several events on the original select field to invoke a behavior in Chosen.</p>
<h3>Example:</h3>
<pre>
<code class="language-javascript">// tell Chosen that a select has changed
$('.my_select_box').trigger('chosen:updated');</code>
</pre>
<table class="docs-table">
<tr>
<th>Event</th><th>Description</th>
</tr>
<tr>
<td>chosen:updated</td>
<td>This event should be triggered whenever Chosen’s underlying select element changes (such as a change in selected options).</td>
</tr>
<tr>
<td>chosen:activate</td>
<td>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.</td>
</tr>
<tr>
<td>chosen:open</td>
<td>This event activates Chosen and also displays the search results.</td>
</tr>
<tr>
<td>chosen:close</td>
<td>This event deactivates Chosen and hides the search results.</td>
</tr>
</table>
<footer>
© 2011–2016 <a href="http://www.getharvest.com/">Harvest</a>. Chosen is licensed under the <a href="https://github.com/harvesthq/chosen/blob/master/LICENSE.md">MIT license</a>.
</footer>
</div>
</div>
<div class="oss-bar">
<ul>
<li><a class="fork" href="https://github.com/harvesthq/chosen">Fork on Github</a></li>
<li><a class="harvest" href="http://www.getharvest.com/">Built by Harvest</a></li>
</ul>
</div>
<script src="docsupport/prism.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>