Revert "Export"
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.1.0 / docs / forms / selects / index.html
1 <!DOCTYPE html>
2 <html>
3         <head>
4         <meta charset="utf-8">
5         <meta name="viewport" content="width=device-width, initial-scale=1">
6         <title>jQuery Mobile Docs - Select</title>
7         <link rel="stylesheet"  href="../../../css/themes/default/jquery.mobile.css" />
8         <link rel="stylesheet" href="../../_assets/css/jqm-docs.css"/>
9         <script src="../../../experiments/themeswitcher/jquery.mobile.themeswitcher.js"></script>
10         <script src="../../../js/jquery.js"></script>
11         <script src="../../../docs/_assets/js/jqm-docs.js"></script>
12         <script src="../../../js/"></script>
13
14 </head>
15 <body>
16
17         <div data-role="page" class="type-interior">
18
19                 <div data-role="header" data-theme="f">
20                 <h1>Select Menus</h1>
21                 <a href="../../../" data-icon="home" data-iconpos="notext" data-direction="reverse">Home</a>
22                 <a href="../../nav.html" data-icon="search" data-iconpos="notext" data-rel="dialog" data-transition="fade">Search</a>
23         </div><!-- /header -->
24
25         <div data-role="content">
26                 <div class="content-primary">
27
28                 <form action="#" method="get">
29
30                         <h2>Select menus</h2>
31                         
32                         <ul data-role="controlgroup" data-type="horizontal" class="localnav">
33                                 <li><a href="index.html" data-role="button" data-transition="fade" class="ui-btn-active">Basics</a></li>
34                                 <li><a href="options.html" data-role="button" data-transition="fade">Options</a></li>
35                                 <li><a href="methods.html" data-role="button" data-transition="fade">Methods</a></li>
36                                 <li><a href="events.html" data-role="button" data-transition="fade">Events</a></li>
37                         </ul>
38                         
39                         <p>The select menu is based on a native <code>select</code> element, which is hidden from view and replaced with a custom-styled select button that matches the look and feel of the jQuery Mobile framework. The select menu is ARIA-enabled and keyboard accessible on the desktop as well. View the <a href="../../api/data-attributes.html">data- attribute reference</a> to see all the possible attributes you can add to selects.</p>
40                         
41                         <p>By default, the framework leverages the native OS options menu to use with the custom button. When the button is clicked, the native OS menu will open. When a value is selected and the menu closes, the custom button's text is updated to match the selected value. Please note that the framework also offers the possibility of having custom (non-native) select menus; see details at the bottom of this page and on the <a href="custom.html"> custom select menu</a> page.</p>
42
43                         <p>To add a select menu to your page, start with a standard <code>select</code> element populated with a set of <code>option</code> elements. Set the <code>for</code> attribute of the <code>label</code> to match the ID of the <code>select</code> so they are semantically associated. It's possible to <a href="../docs-forms.html">accessibly hide the label</a> if it's not desired in the page layout, but we require that it is present in the markup for semantic and accessibility reasons.  </p>
44                         
45                         <p>The framework will find all <code>select</code> elements and automatically enhance them into select menus, no need to apply a <code>data-role</code> attribute. To prevent the automatic enhancement of a select, add  <code>data-role="none"</code> attribute to the <code>select</code>.</p>
46                         
47 <pre><code>
48 &lt;label for=&quot;select-choice-0&quot; class=&quot;select&quot;&gt;Shipping method:&lt;/label&gt;
49 &lt;select name=&quot;select-choice-0&quot; id=&quot;select-choice-1&quot;&gt;
50    &lt;option value=&quot;standard&quot;&gt;Standard: 7 day&lt;/option&gt;
51    &lt;option value=&quot;rush&quot;&gt;Rush: 3 days&lt;/option&gt;
52    &lt;option value=&quot;express&quot;&gt;Express: next day&lt;/option&gt;
53    &lt;option value=&quot;overnight&quot;&gt;Overnight&lt;/option&gt;
54 &lt;/select&gt;
55 </code></pre>
56
57                         <p>This will produce a basic select menu. The default styles set the width of the input to 100% of the parent container and stacks the label on a separate line.</p>
58
59                         <label for="select-choice-0" class="select">Shipping method:</label>
60                         <select name="select-choice-0" id="select-choice-1">
61                                 <option value="standard">Standard: 7 day</option>
62                                 <option value="rush">Rush: 3 days</option>
63                                 <option value="express">Express: next day</option>
64                                 <option value="overnight">Overnight</option>
65                         </select>
66
67                         <h2>Mini version</h2>
68
69                         <p>For a more compact version that is useful in toolbars and tight spaces, add the <code>data-mini="true"</code> attribute to the element to create a <a href="../forms-all-mini.html">mini version</a>. </p>
70
71 <pre><code>     
72 &lt;label for=&quot;select-choice-min&quot; class=&quot;select&quot;&gt;Shipping method:&lt;/label&gt;
73 &lt;select name=&quot;select-choice-min&quot; id=&quot;select-choice-1&quot; <strong>data-mini=&quot;true&quot;</strong>&gt;
74    &lt;option value=&quot;standard&quot;&gt;Standard: 7 day&lt;/option&gt;
75    &lt;option value=&quot;rush&quot;&gt;Rush: 3 days&lt;/option&gt;
76    &lt;option value=&quot;express&quot;&gt;Express: next day&lt;/option&gt;
77    &lt;option value=&quot;overnight&quot;&gt;Overnight&lt;/option&gt;
78 &lt;/select&gt; 
79 </code></pre>
80                         
81                         <p>This will produce a select that a not as tall as the standard version and has a smaller text size.</p>
82                         <label for="select-choice-min" class="select">Shipping method:</label>
83                         <select name="select-choice-0" id="select-choice-min" data-mini="true">
84                                 <option value="standard">Standard: 7 day</option>
85                                 <option value="rush">Rush: 3 days</option>
86                                 <option value="express">Express: next day</option>
87                                 <option value="overnight">Overnight</option>
88                         </select>
89
90                         <h2>Field containers</h2>
91                         <p>Optionally wrap the selects in a container with the <code>data-role="fieldcontain"</code> attribute to help visually group it in a longer form.</p>
92 <pre><code>
93 <strong>&lt;div data-role=&quot;fieldcontain&quot;&gt;
94 </strong>   &lt;label for=&quot;select-choice-1&quot; class=&quot;select&quot;&gt;Shipping method:&lt;/label&gt;
95    &lt;select name=&quot;select-choice-1&quot; id=&quot;select-choice-1&quot;&gt;
96       &lt;option value=&quot;standard&quot;&gt;Standard: 7 day&lt;/option&gt;
97       &lt;option value=&quot;rush&quot;&gt;Rush: 3 days&lt;/option&gt;
98       &lt;option value=&quot;express&quot;&gt;Express: next day&lt;/option&gt;
99       &lt;option value=&quot;overnight&quot;&gt;Overnight&lt;/option&gt;
100    &lt;/select&gt;
101 <strong>&lt;/div&gt;
102 </strong></code></pre>
103
104                         <p>The select input is now displayed like this:</p>
105
106
107 <div data-role="fieldcontain">
108         <label for="select-choice-1" class="select">Shipping method:</label>
109         <select name="select-choice-1" id="select-choice-1">
110                 <option value="standard">Standard: 7 day</option>
111                 <option value="rush">Rush: 3 days</option>
112                 <option value="express">Express: next day</option>
113                 <option value="overnight">Overnight</option>
114         </select>
115 </div>
116
117 <p>An example of a select with a long list of options:</p>
118
119 <div data-role="fieldcontain">
120         <label for="select-choice-2" class="select">Your state:</label>
121         <select name="select-choice-2" id="select-choice-2">
122                 <option value="AL">Alabama</option>
123                 <option value="AK">Alaska</option>
124                 <option value="AZ">Arizona</option>
125                 <option value="AR">Arkansas</option>
126                 <option value="CA">California</option>
127                 <option value="CO">Colorado</option>
128                 <option value="CT">Connecticut</option>
129                 <option value="DE">Delaware</option>
130                 <option value="FL">Florida</option>
131                 <option value="GA">Georgia</option>
132                 <option value="HI">Hawaii</option>
133                 <option value="ID">Idaho</option>
134                 <option value="IL">Illinois</option>
135                 <option value="IN">Indiana</option>
136                 <option value="IA">Iowa</option>
137                 <option value="KS">Kansas</option>
138                 <option value="KY">Kentucky</option>
139                 <option value="LA">Louisiana</option>
140                 <option value="ME">Maine</option>
141                 <option value="MD">Maryland</option>
142                 <option value="MA">Massachusetts</option>
143                 <option value="MI">Michigan</option>
144                 <option value="MN">Minnesota</option>
145                 <option value="MS">Mississippi</option>
146                 <option value="MO">Missouri</option>
147                 <option value="MT">Montana</option>
148                 <option value="NE">Nebraska</option>
149                 <option value="NV">Nevada</option>
150                 <option value="NH">New Hampshire</option>
151                 <option value="NJ">New Jersey</option>
152                 <option value="NM">New Mexico</option>
153                 <option value="NY">New York</option>
154                 <option value="NC">North Carolina</option>
155                 <option value="ND">North Dakota</option>
156                 <option value="OH">Ohio</option>
157                 <option value="OK">Oklahoma</option>
158                 <option value="OR">Oregon</option>
159                 <option value="PA">Pennsylvania</option>
160                 <option value="RI">Rhode Island</option>
161                 <option value="SC">South Carolina</option>
162                 <option value="SD">South Dakota</option>
163                 <option value="TN">Tennessee</option>
164                 <option value="TX">Texas</option>
165                 <option value="UT">Utah</option>
166                 <option value="VT">Vermont</option>
167                 <option value="VA">Virginia</option>
168                 <option value="WA">Washington</option>
169                 <option value="WV">West Virginia</option>
170                 <option value="WI">Wisconsin</option>
171                 <option value="WY">Wyoming</option>
172         </select>
173 </div>
174
175 <h2>Optgroups</h2>
176 <p>The following example organizes the options into <code>optgroup</code> elements. Support for this feature in mobile selects is a bit spotty, but is improving.</p>
177
178 <div data-role="fieldcontain">
179         <label for="select-choice-nc" class="select">Preferred delivery:</label>
180         <select name="select-choice-8" id="select-choice-nc">
181                 <optgroup label="FedEx">
182                         <option value="firstOvernight">First Overnight</option>
183                         <option value="expressSaver">Express Saver</option>
184                         <option value="ground">Ground</option>
185                 </optgroup>
186                 <optgroup label="UPS">
187                         <option value="firstOvernight">First Overnight</option>
188                         <option value="expressSaver">Express Saver</option>
189                         <option value="ground">Ground</option>
190                 </optgroup>
191                 <optgroup label="US Mail">
192                         <option value="standard">Standard: 7 day</option>
193                         <option value="rush">Rush: 3 days</option>
194                         <option value="express">Express: next day (disabled)</option>
195                         <option value="overnight">Overnight</option>
196                 </optgroup>
197         </select>
198 </div>
199
200
201
202 <h2>Vertically grouped select inputs</h2>
203
204 <p>To create a grouped set of select inputs, first add <code>select</code> and a corresponding <code>label</code>. Set the <code>for</code> attribute of the <code>label</code> to match the ID of the <code>select</code> so they are semantically associated.</p>
205
206 <p>Because the <code>label</code> element will be associated with each individual select input, we recommend wrapping the selects in a <code>fieldset</code> element that has a <code>legend</code> which acts as the combined label for the grouped inputs.</p>
207
208 <p>Lastly, one needs to wrap the <code>fieldset</code> in a <code>div</code> with <code> data-role="controlgroup"</code> attribute, so it can be styled as a group.</p>
209                         
210 <pre><code>     
211 &lt;div data-role=&quot;fieldcontain&quot;&gt;
212 &lt;fieldset data-role=&quot;controlgroup&quot;&gt;
213         &lt;legend&gt;Date of Birth:&lt;/legend&gt;
214
215     &lt;label for="select-choice-month">Month&lt;/label&gt;
216 &lt;select name="select-choice-month" id="select-choice-month"&gt;
217         &lt;option&gt;Month&lt;/option&gt;
218         &lt;option value="jan"&gt;January&lt;/option&gt;
219         &lt;!-- etc. --&gt;
220 &lt;/select&gt;
221
222         &lt;label for="select-choice-day">Day&lt;/label&gt;
223 &lt;select name="select-choice-day" id="select-choice-day"&gt;
224         &lt;option&gt;Day&lt;/option&gt;
225         &lt;option value="1"&gt;1&lt;/option&gt;
226         &lt;!-- etc. --&gt;
227 &lt;/select&gt;
228
229 &lt;label for="select-choice-year">Year&lt;/label&gt;
230 &lt;select name="select-choice-year" id="select-choice-year"&gt;
231         &lt;option&gt;Year&lt;/option&gt;
232         &lt;option value="2011"&gt;2011&lt;/option&gt;
233         &lt;!-- etc. --&gt;
234 &lt;/select&gt;
235 &lt;/fieldset&gt;
236 &lt;/div&gt;
237 </code></pre>
238
239         <div data-role="fieldcontain">
240         <fieldset data-role="controlgroup">
241                 <legend>Date of Birth:</legend>
242                 
243                 <label for="select-choice-month">Month</label>
244                 <select name="select-choice-month" id="select-choice-month">
245                         <option>Month</option>
246                         <option value="jan">January</option>
247                         <option value="dec">December</option>
248                         <option value="feb">February</option>
249                         <option value="mar">March</option>
250                         <option value="apr">April</option>
251                         <option value="may">May</option>
252                         <option value="jun">June</option>
253                         <option value="jul">July</option>
254                         <option value="aug">August</option>
255                         <option value="sep">September</option>
256                         <option value="oct">October</option>
257                         <option value="nov">November</option>
258                         <option value="dec">December</option>
259                 </select>
260
261                 <label for="select-choice-day">Day</label>
262                 <select name="select-choice-day" id="select-choice-day">
263                         <option>Day</option>
264                         <option value="1">1</option>
265                         <option value="2">2</option>
266                         <option value="3">3</option>
267                         <option value="4">4</option>
268                         <option value="5">5</option>
269                         <option value="6">6</option>
270                         <option value="7">7</option>
271                 </select>
272
273                 <label for="select-choice-year">Year</label>
274                 <select name="select-choice-year" id="select-choice-year">
275                         <option>Year</option>
276                         <option value="2011">2011</option>
277                         <option value="2010">2010</option>
278                         <option value="2009">2009</option>
279                         <option value="2008">2008</option>
280                         <option value="2007">2007</option>
281                         <option value="2006">2006</option>
282                         <option value="2005">2005</option>
283                         <option value="2004">2004</option>
284                 </select>
285         </fieldset>
286
287 </div>
288
289 <h2>Horizontally grouped select inputs</h2>
290 <p>Select inputs can also be used for grouped sets with more than one related selections. To make a horizontal button set, add the <code>data-type="horizontal"</code> to the fieldset. Note that the buttons which trigger the select will resize depending on the currently selected option’s value. Note that browsers without support for <code>display: inline-block;</code> will group the selects vertically, as above.</p>
291
292 <code>
293 &lt;fieldset data-role="controlgroup" <strong>data-type="horizontal"</strong>&gt;
294 </code>
295
296         <fieldset data-role="controlgroup" data-type="horizontal">
297                 <legend>Date of Birth:</legend>
298                 
299                 <label for="select-choice-month">Month</label>
300                 <select name="select-choice-month" id="select-choice-month">
301                         <option value="jan">Jan</option>
302                         <option value="dec">Dec</option>
303                         <option value="feb">Feb</option>
304                         <option value="mar">Mar</option>
305                         <option value="apr">Apr</option>
306                         <option value="may">May</option>
307                         <option value="jun">Jun</option>
308                         <option value="jul">Jul</option>
309                         <option value="aug">Aug</option>
310                         <option value="sep">Sep</option>
311                         <option value="oct">Oct</option>
312                         <option value="nov">Nov</option>
313                         <option value="dec">Dec</option>
314                 </select>
315
316                 <label for="select-choice-day">Day</label>
317                 <select name="select-choice-day" id="select-choice-day">
318                         <option value="1">1</option>
319                         <option value="2">2</option>
320                         <option value="3">3</option>
321                         <option value="4">4</option>
322                         <option value="5">5</option>
323                         <option value="6">6</option>
324                         <option value="7">7</option>
325                         <option value="8">8</option>
326                         <option value="9">9</option>
327                         <option value="10">10</option>
328                         <option value="11">11</option>
329                         <option value="12">13</option>
330                         <option value="13">14</option>
331                         <option value="15">15</option>
332                 </select>
333
334                 <label for="select-choice-year">Year</label>
335                 <select name="select-choice-year" id="select-choice-year">
336                         <option value="2011">2012</option>
337                         <option value="2011">2011</option>
338                         <option value="2010">2010</option>
339                         <option value="2009">2009</option>
340                         <option value="2008">2008</option>
341                         <option value="2007">2007</option>
342                         <option value="2006">2006</option>
343                         <option value="2005">2005</option>
344                         <option value="2004">2004</option>
345                 </select>
346         </fieldset>
347         
348 <h2>Calling the select menu plugin</h2>
349 <p>The select menu plugin will auto initialize on any page that contains a select menu, without any need for a <code>data-role</code> attribute in the markup. However, you can directly call the select menu plugin on any selector, just like any normal jQuery plugin:</p>
350 <pre><code>
351 $('select').selectmenu();                       
352 </code></pre>
353     
354         </form>
355         
356         
357         <h2>Theming selects</h2>
358         <p>You can specify any jQuery Mobile button <code>data-</code> attribute on a select element, too. In this example, we're setting the theme, icon and inline properties:</p>
359
360         <div data-role="fieldcontain">
361                 <label for="select-choice-11" class="select">Actions</label>
362                 <select name="select-choice-11" id="select-choice-11" data-theme="e" data-icon="gear" data-inline="true">
363                         <option value="view">User details</option>
364                         <option value="edit">Edit user</option>
365                         <option value="deactivate">De-activate</option>
366                         <option value="delete">Delete user</option>
367                 </select>
368         </div>
369     
370         
371         <h2>Custom select menus</h2>
372         <p>For the sake of advanced styling, the framework also offers a method of generating <a href="custom.html">custom menus</a> from existing select menu markup  instead of the native OS menu. The custom menu supports disabled options and multiple selection (whereas native mobile OS support for both is inconsistent), adds an elegant way to handle placeholder values, and restores missing functionality on certain platforms such as <code>optgroup</code> support on Android.
373                 
374         <div align="right"><a href="custom.html" data-role="button" data-icon="arrow-r" data-iconpos="right" data-inline="true" align="right">Custom select menu docs</a>
375 </div>
376                 </p>
377         
378         </div><!--/content-primary -->          
379         
380         <div class="content-secondary">
381                 
382                 <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
383                         
384                                 <h3>More in this section</h3>
385                                 
386                                 <ul data-role="listview" data-theme="c" data-dividertheme="d">
387                                 
388                                         <li data-role="list-divider">Form elements</li>
389                                         <li><a href="../docs-forms.html">Form basics</a></li>
390                                         <li><a href="../forms-all.html">Form element gallery</a></li>
391                                         <li><a href="../forms-all-mini.html">Mini form element gallery</a></li>
392                                         <li><a href="../textinputs/index.html">Text inputs</a></li>
393                                         <li><a href="../search/">Search input</a></li>
394                                         <li><a href="../slider/">Slider</a></li>
395                                         <li><a href="../switch/">Flip toggle switch</a></li>
396                                         <li><a href="../radiobuttons/">Radio buttons</a></li>
397                                         <li><a href="../checkboxes/">Checkboxes</a></li>
398                                         <li data-theme="a"><a href="index.html">Select menus</a></li>
399                                         <li><a href="../forms-themes.html">Theming forms</a></li>
400                                         <li><a href="../forms-all-native.html">Native form elements</a></li>
401                                         <li><a href="../forms-sample.html">Submitting forms</a></li>
402                                         
403         
404                                 </ul>
405                 </div>
406         </div>          
407
408 </div><!-- /content -->
409
410 <div data-role="footer" class="footer-docs" data-theme="c">
411                 <p>&copy; 2011-12 The jQuery Foundation</p>
412 </div>
413         
414 </div><!-- /page -->
415
416 </body>
417 </html>
418