Tizen 2.0 Release
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.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="../../../js/jquery.js"></script>
10         <script src="../../../docs/_assets/js/jqm-docs.js"></script>
11         <script src="../../../js/"></script>
12
13 </head>
14 <body>
15
16         <div data-role="page" class="type-interior">
17
18                 <div data-role="header" data-theme="f">
19                 <h1>Select Menus</h1>
20                 <a href="../../../" data-icon="home" data-iconpos="notext" data-direction="reverse">Home</a>
21                 <a href="../../nav.html" data-icon="search" data-iconpos="notext" data-rel="dialog" data-transition="fade">Search</a>
22         </div><!-- /header -->
23
24         <div data-role="content">
25                 <div class="content-primary">
26
27                 <form action="#" method="get">
28
29                         <h2>Select menus</h2>
30                         
31                         <ul data-role="controlgroup" data-type="horizontal" class="localnav">
32                                 <li><a href="index.html" data-role="button" data-transition="fade" class="ui-btn-active">Basics</a></li>
33                                 <li><a href="options.html" data-role="button" data-transition="fade">Options</a></li>
34                                 <li><a href="methods.html" data-role="button" data-transition="fade">Methods</a></li>
35                                 <li><a href="events.html" data-role="button" data-transition="fade">Events</a></li>
36                         </ul>
37                         
38                         <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>
39                         
40                         <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>
41
42                         <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 <code>id</code> 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>
43                         
44                         <p>The framework will find all <code>select</code> elements and automatically enhance them into select menus; there is 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>
45                         
46 <pre><code>
47 &lt;label for=&quot;select-choice-0&quot; class=&quot;select&quot;&gt;Shipping method:&lt;/label&gt;
48 &lt;select name=&quot;select-choice-0&quot; id=&quot;select-choice-0&quot;&gt;
49    &lt;option value=&quot;standard&quot;&gt;Standard: 7 day&lt;/option&gt;
50    &lt;option value=&quot;rush&quot;&gt;Rush: 3 days&lt;/option&gt;
51    &lt;option value=&quot;express&quot;&gt;Express: next day&lt;/option&gt;
52    &lt;option value=&quot;overnight&quot;&gt;Overnight&lt;/option&gt;
53 &lt;/select&gt;
54 </code></pre>
55
56                         <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>
57
58                         <label for="select-choice-0" class="select">Shipping method:</label>
59                         <select name="select-choice-0" id="select-choice-0">
60                                 <option value="standard">Standard: 7 day</option>
61                                 <option value="rush">Rush: 3 days</option>
62                                 <option value="express">Express: next day</option>
63                                 <option value="overnight">Overnight</option>
64                         </select>
65
66                         <h2>Mini version</h2>
67
68                         <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>
69
70 <pre><code>     
71 &lt;label for=&quot;select-choice-min&quot; class=&quot;select&quot;&gt;Shipping method:&lt;/label&gt;
72 &lt;select name=&quot;select-choice-min&quot; id=&quot;select-choice-min&quot; <strong>data-mini=&quot;true&quot;</strong>&gt;
73    &lt;option value=&quot;standard&quot;&gt;Standard: 7 day&lt;/option&gt;
74    &lt;option value=&quot;rush&quot;&gt;Rush: 3 days&lt;/option&gt;
75    &lt;option value=&quot;express&quot;&gt;Express: next day&lt;/option&gt;
76    &lt;option value=&quot;overnight&quot;&gt;Overnight&lt;/option&gt;
77 &lt;/select&gt; 
78 </code></pre>
79                         
80                         <p>This will produce a select that a not as tall as the standard version and has a smaller text size.</p>
81                         <label for="select-choice-min" class="select">Shipping method:</label>
82                         <select name="select-choice-min" id="select-choice-min" data-mini="true">
83                                 <option value="standard">Standard: 7 day</option>
84                                 <option value="rush">Rush: 3 days</option>
85                                 <option value="express">Express: next day</option>
86                                 <option value="overnight">Overnight</option>
87                         </select>
88
89                         <h2>Field containers</h2>
90                         <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>
91 <pre><code>
92 <strong>&lt;div data-role=&quot;fieldcontain&quot;&gt;
93 </strong>   &lt;label for=&quot;select-choice-1&quot; class=&quot;select&quot;&gt;Shipping method:&lt;/label&gt;
94    &lt;select name=&quot;select-choice-1&quot; id=&quot;select-choice-1&quot;&gt;
95       &lt;option value=&quot;standard&quot;&gt;Standard: 7 day&lt;/option&gt;
96       &lt;option value=&quot;rush&quot;&gt;Rush: 3 days&lt;/option&gt;
97       &lt;option value=&quot;express&quot;&gt;Express: next day&lt;/option&gt;
98       &lt;option value=&quot;overnight&quot;&gt;Overnight&lt;/option&gt;
99    &lt;/select&gt;
100 <strong>&lt;/div&gt;
101 </strong></code></pre>
102
103                         <p>The select input is now displayed like this:</p>
104
105
106 <div data-role="fieldcontain">
107         <label for="select-choice-1" class="select">Shipping method:</label>
108         <select name="select-choice-1" id="select-choice-1">
109                 <option value="standard">Standard: 7 day</option>
110                 <option value="rush">Rush: 3 days</option>
111                 <option value="express">Express: next day</option>
112                 <option value="overnight">Overnight</option>
113         </select>
114 </div>
115
116 <p>An example of a select with a long list of options:</p>
117
118 <div data-role="fieldcontain">
119         <label for="select-choice-2" class="select">Your state:</label>
120         <select name="select-choice-2" id="select-choice-2">
121                 <option value="AL">Alabama</option>
122                 <option value="AK">Alaska</option>
123                 <option value="AZ">Arizona</option>
124                 <option value="AR">Arkansas</option>
125                 <option value="CA">California</option>
126                 <option value="CO">Colorado</option>
127                 <option value="CT">Connecticut</option>
128                 <option value="DE">Delaware</option>
129                 <option value="FL">Florida</option>
130                 <option value="GA">Georgia</option>
131                 <option value="HI">Hawaii</option>
132                 <option value="ID">Idaho</option>
133                 <option value="IL">Illinois</option>
134                 <option value="IN">Indiana</option>
135                 <option value="IA">Iowa</option>
136                 <option value="KS">Kansas</option>
137                 <option value="KY">Kentucky</option>
138                 <option value="LA">Louisiana</option>
139                 <option value="ME">Maine</option>
140                 <option value="MD">Maryland</option>
141                 <option value="MA">Massachusetts</option>
142                 <option value="MI">Michigan</option>
143                 <option value="MN">Minnesota</option>
144                 <option value="MS">Mississippi</option>
145                 <option value="MO">Missouri</option>
146                 <option value="MT">Montana</option>
147                 <option value="NE">Nebraska</option>
148                 <option value="NV">Nevada</option>
149                 <option value="NH">New Hampshire</option>
150                 <option value="NJ">New Jersey</option>
151                 <option value="NM">New Mexico</option>
152                 <option value="NY">New York</option>
153                 <option value="NC">North Carolina</option>
154                 <option value="ND">North Dakota</option>
155                 <option value="OH">Ohio</option>
156                 <option value="OK">Oklahoma</option>
157                 <option value="OR">Oregon</option>
158                 <option value="PA">Pennsylvania</option>
159                 <option value="RI">Rhode Island</option>
160                 <option value="SC">South Carolina</option>
161                 <option value="SD">South Dakota</option>
162                 <option value="TN">Tennessee</option>
163                 <option value="TX">Texas</option>
164                 <option value="UT">Utah</option>
165                 <option value="VT">Vermont</option>
166                 <option value="VA">Virginia</option>
167                 <option value="WA">Washington</option>
168                 <option value="WV">West Virginia</option>
169                 <option value="WI">Wisconsin</option>
170                 <option value="WY">Wyoming</option>
171         </select>
172 </div>
173
174 <h2>Optgroups</h2>
175 <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>
176
177 <div data-role="fieldcontain">
178         <label for="select-choice-nc" class="select">Preferred delivery:</label>
179         <select name="select-choice-8" id="select-choice-nc">
180                 <optgroup label="FedEx">
181                         <option value="firstOvernight">First Overnight</option>
182                         <option value="expressSaver">Express Saver</option>
183                         <option value="ground">Ground</option>
184                 </optgroup>
185                 <optgroup label="UPS">
186                         <option value="firstOvernight">First Overnight</option>
187                         <option value="expressSaver">Express Saver</option>
188                         <option value="ground">Ground</option>
189                 </optgroup>
190                 <optgroup label="US Mail">
191                         <option value="standard">Standard: 7 day</option>
192                         <option value="rush">Rush: 3 days</option>
193                         <option value="express">Express: next day (disabled)</option>
194                         <option value="overnight">Overnight</option>
195                 </optgroup>
196         </select>
197 </div>
198
199
200
201 <h2>Vertically grouped select inputs</h2>
202
203 <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 <code>id</code> of the <code>select</code> so they are semantically associated.</p>
204
205 <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>
206
207 <p>Lastly, one needs to add the <code>data-role="controlgroup"</code> attribute to the <code>fieldset</code>, so it will be styled as a group.</p>
208                         
209 <pre><code>     
210 &lt;div data-role=&quot;fieldcontain&quot;&gt;
211     &lt;fieldset data-role=&quot;controlgroup&quot;&gt;
212         &lt;legend&gt;Date of Birth:&lt;/legend&gt;
213     
214         &lt;label for="select-choice-month">Month&lt;/label&gt;
215         &lt;select name="select-choice-month" id="select-choice-month"&gt;
216             &lt;option&gt;Month&lt;/option&gt;
217             &lt;option value="jan"&gt;January&lt;/option&gt;
218             &lt;!-- etc. --&gt;
219         &lt;/select&gt;
220     
221         &lt;label for="select-choice-day">Day&lt;/label&gt;
222         &lt;select name="select-choice-day" id="select-choice-day"&gt;
223             &lt;option&gt;Day&lt;/option&gt;
224             &lt;option value="1"&gt;1&lt;/option&gt;
225             &lt;!-- etc. --&gt;
226         &lt;/select&gt;
227     
228         &lt;label for="select-choice-year">Year&lt;/label&gt;
229         &lt;select name="select-choice-year" id="select-choice-year"&gt;
230             &lt;option&gt;Year&lt;/option&gt;
231             &lt;option value="2011"&gt;2011&lt;/option&gt;
232             &lt;!-- etc. --&gt;
233         &lt;/select&gt;
234         
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         </div>
287
288 <h2>Horizontally grouped select inputs</h2>
289 <p>Select inputs can also be used for grouped sets with more than one related selection. 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>
290
291 <code>
292 &lt;fieldset data-role="controlgroup" <strong>data-type="horizontal"</strong>&gt;
293 </code>
294
295         <fieldset data-role="controlgroup" data-type="horizontal">
296                 <legend>Date of Birth:</legend>
297                 
298                 <label for="select-choice-month">Month</label>
299                 <select name="select-choice-month" id="select-choice-month">
300                         <option value="jan">Jan</option>
301                         <option value="dec">Dec</option>
302                         <option value="feb">Feb</option>
303                         <option value="mar">Mar</option>
304                         <option value="apr">Apr</option>
305                         <option value="may">May</option>
306                         <option value="jun">Jun</option>
307                         <option value="jul">Jul</option>
308                         <option value="aug">Aug</option>
309                         <option value="sep">Sep</option>
310                         <option value="oct">Oct</option>
311                         <option value="nov">Nov</option>
312                         <option value="dec">Dec</option>
313                 </select>
314
315                 <label for="select-choice-day">Day</label>
316                 <select name="select-choice-day" id="select-choice-day">
317                         <option value="1">1</option>
318                         <option value="2">2</option>
319                         <option value="3">3</option>
320                         <option value="4">4</option>
321                         <option value="5">5</option>
322                         <option value="6">6</option>
323                         <option value="7">7</option>
324                         <option value="8">8</option>
325                         <option value="9">9</option>
326                         <option value="10">10</option>
327                         <option value="11">11</option>
328                         <option value="12">13</option>
329                         <option value="13">14</option>
330                         <option value="15">15</option>
331                 </select>
332
333                 <label for="select-choice-year">Year</label>
334                 <select name="select-choice-year" id="select-choice-year">
335                         <option value="2011">2012</option>
336                         <option value="2011">2011</option>
337                         <option value="2010">2010</option>
338                         <option value="2009">2009</option>
339                         <option value="2008">2008</option>
340                         <option value="2007">2007</option>
341                         <option value="2006">2006</option>
342                         <option value="2005">2005</option>
343                         <option value="2004">2004</option>
344                 </select>
345         </fieldset>
346         
347 <h2>Calling the select menu plugin</h2>
348 <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>
349 <pre><code>
350 $('select').selectmenu();                       
351 </code></pre>
352     
353         </form>
354         
355         
356         <h2>Theming selects</h2>
357         <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>
358
359         <div data-role="fieldcontain">
360                 <label for="select-choice-11" class="select">Actions</label>
361                 <select name="select-choice-11" id="select-choice-11" data-theme="e" data-icon="gear" data-inline="true">
362                         <option value="view">User details</option>
363                         <option value="edit">Edit user</option>
364                         <option value="deactivate">De-activate</option>
365                         <option value="delete">Delete user</option>
366                 </select>
367         </div>
368     
369         
370         <h2>Custom select menus</h2>
371         <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.
372                 
373         <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>
374 </div>
375                 </p>
376         
377         </div><!--/content-primary -->          
378         
379         <div class="content-secondary">
380                 
381                 <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
382                         
383                                 <h3>More in this section</h3>
384                                 
385                                 <ul data-role="listview" data-theme="c" data-dividertheme="d">
386                                 
387                                         <li data-role="list-divider">Form elements</li>
388                                         <li><a href="../docs-forms.html">Form basics</a></li>
389                                         <li><a href="../forms-all.html">Form element gallery</a></li>
390                                         <li><a href="../forms-all-mini.html">Mini form element gallery</a></li>
391                                         <li><a href="../textinputs/index.html">Text inputs</a></li>
392                                         <li><a href="../search/">Search input</a></li>
393                                         <li><a href="../slider/">Slider</a></li>
394                                         <li><a href="../switch/">Flip toggle switch</a></li>
395                                         <li><a href="../radiobuttons/">Radio buttons</a></li>
396                                         <li><a href="../checkboxes/">Checkboxes</a></li>
397                                         <li data-theme="a"><a href="index.html">Select menus</a></li>
398                                         <li><a href="../forms-themes.html">Theming forms</a></li>
399                                         <li><a href="../forms-all-native.html">Native form elements</a></li>
400                                         <li><a href="../forms-sample.html">Submitting forms</a></li>
401                                         
402         
403                                 </ul>
404                 </div>
405         </div>          
406
407 </div><!-- /content -->
408
409 <div data-role="footer" class="footer-docs" data-theme="c">
410                 <p class="jqm-version"></p>
411                 <p>&copy; 2012 jQuery Foundation and other contributors</p>
412 </div>
413         
414 </div><!-- /page -->
415
416 </body>
417 </html>
418