446c3944a65ac9da39026ce5809aad131ee76c1d
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / 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/" />
8         <link rel="stylesheet" href="../../_assets/css/jqm-docs.css"/>
9         <script src="../../../js/jquery.js"></script>
10         <script src="../../../experiments/themeswitcher/jquery.mobile.themeswitcher.js"></script>
11         <script src="../../_assets/js/jqm-docs.js"></script>
12         <script src="../../../js/"></script>
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" class="ui-btn-right jqm-home">Home</a>
21         </div><!-- /header -->
22
23         <div data-role="content">
24                 <div class="content-primary">
25
26                 <form action="#" method="get">
27
28                         <h2>Select menus</h2>
29                         
30                         <ul data-role="controlgroup" data-type="horizontal" class="localnav">
31                                 <li><a href="index.html" data-role="button" data-transition="fade" class="ui-btn-active">Basics</a></li>
32                                 <li><a href="options.html" data-role="button" data-transition="fade">Options</a></li>
33                                 <li><a href="methods.html" data-role="button" data-transition="fade">Methods</a></li>
34                                 <li><a href="events.html" data-role="button" data-transition="fade">Events</a></li>
35                         </ul>
36                         
37                         <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>
38                         
39                         <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.</p>
40
41                         <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>
42                         
43                         <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>
44                         
45                         <pre><code>
46 &lt;label for=&quot;select-choice-0&quot; class=&quot;select&quot;&gt;Shipping method:&lt;/label&gt;
47 &lt;select name=&quot;select-choice-0&quot; id=&quot;select-choice-1&quot;&gt;
48    &lt;option value=&quot;standard&quot;&gt;Standard: 7 day&lt;/option&gt;
49    &lt;option value=&quot;rush&quot;&gt;Rush: 3 days&lt;/option&gt;
50    &lt;option value=&quot;express&quot;&gt;Express: next day&lt;/option&gt;
51    &lt;option value=&quot;overnight&quot;&gt;Overnight&lt;/option&gt;
52 &lt;/select&gt;
53                         </code></pre>
54
55                         <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>
56
57                                 <label for="select-choice-0" class="select">Shipping method:</label>
58                                 <select name="select-choice-0" id="select-choice-1">
59                                         <option value="standard">Standard: 7 day</option>
60                                         <option value="rush">Rush: 3 days</option>
61                                         <option value="express">Express: next day</option>
62                                         <option value="overnight">Overnight</option>
63                                 </select>
64
65                         
66                         <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>
67 <pre><code>
68 <strong>&lt;div data-role=&quot;fieldcontain&quot;&gt;
69 </strong>   &lt;label for=&quot;select-choice-1&quot; class=&quot;select&quot;&gt;Shipping method:&lt;/label&gt;
70    &lt;select name=&quot;select-choice-1&quot; id=&quot;select-choice-1&quot;&gt;
71       &lt;option value=&quot;standard&quot;&gt;Standard: 7 day&lt;/option&gt;
72       &lt;option value=&quot;rush&quot;&gt;Rush: 3 days&lt;/option&gt;
73       &lt;option value=&quot;express&quot;&gt;Express: next day&lt;/option&gt;
74       &lt;option value=&quot;overnight&quot;&gt;Overnight&lt;/option&gt;
75    &lt;/select&gt;
76 <strong>&lt;/div&gt;
77 </strong></code></pre>
78
79                         <p>The select input is now displayed like this:</p>
80
81
82 <div data-role="fieldcontain">
83         <label for="select-choice-1" class="select">Shipping method:</label>
84         <select name="select-choice-1" id="select-choice-1">
85                 <option value="standard">Standard: 7 day</option>
86                 <option value="rush">Rush: 3 days</option>
87                 <option value="express">Express: next day</option>
88                 <option value="overnight">Overnight</option>
89         </select>
90 </div>
91
92 <p>An example of a select with a long list of options:</p>
93
94 <div data-role="fieldcontain">
95         <label for="select-choice-2" class="select">Your state:</label>
96         <select name="select-choice-2" id="select-choice-2">
97                 <option value="AL">Alabama</option>
98                 <option value="AK">Alaska</option>
99                 <option value="AZ">Arizona</option>
100                 <option value="AR">Arkansas</option>
101                 <option value="CA">California</option>
102                 <option value="CO">Colorado</option>
103                 <option value="CT">Connecticut</option>
104                 <option value="DE">Delaware</option>
105                 <option value="FL">Florida</option>
106                 <option value="GA">Georgia</option>
107                 <option value="HI">Hawaii</option>
108                 <option value="ID">Idaho</option>
109                 <option value="IL">Illinois</option>
110                 <option value="IN">Indiana</option>
111                 <option value="IA">Iowa</option>
112                 <option value="KS">Kansas</option>
113                 <option value="KY">Kentucky</option>
114                 <option value="LA">Louisiana</option>
115                 <option value="ME">Maine</option>
116                 <option value="MD">Maryland</option>
117                 <option value="MA">Massachusetts</option>
118                 <option value="MI">Michigan</option>
119                 <option value="MN">Minnesota</option>
120                 <option value="MS">Mississippi</option>
121                 <option value="MO">Missouri</option>
122                 <option value="MT">Montana</option>
123                 <option value="NE">Nebraska</option>
124                 <option value="NV">Nevada</option>
125                 <option value="NH">New Hampshire</option>
126                 <option value="NJ">New Jersey</option>
127                 <option value="NM">New Mexico</option>
128                 <option value="NY">New York</option>
129                 <option value="NC">North Carolina</option>
130                 <option value="ND">North Dakota</option>
131                 <option value="OH">Ohio</option>
132                 <option value="OK">Oklahoma</option>
133                 <option value="OR">Oregon</option>
134                 <option value="PA">Pennsylvania</option>
135                 <option value="RI">Rhode Island</option>
136                 <option value="SC">South Carolina</option>
137                 <option value="SD">South Dakota</option>
138                 <option value="TN">Tennessee</option>
139                 <option value="TX">Texas</option>
140                 <option value="UT">Utah</option>
141                 <option value="VT">Vermont</option>
142                 <option value="VA">Virginia</option>
143                 <option value="WA">Washington</option>
144                 <option value="WV">West Virginia</option>
145                 <option value="WI">Wisconsin</option>
146                 <option value="WY">Wyoming</option>
147         </select>
148 </div>
149
150 <!--
151 <p>The following example organizes the options into <code>optgroup</code> elements:</p>
152
153 <div data-role="fieldcontain">
154         <label for="select-choice-nc" class="select">Preferred delivery:</label>
155         <select name="select-choice-8" id="select-choice-nc">
156                 <optgroup label="FedEx">
157                         <option value="firstOvernight">First Overnight</option>
158                         <option value="expressSaver">Express Saver</option>
159                         <option value="ground">Ground</option>
160                 </optgroup>
161                 <optgroup label="UPS">
162                         <option value="firstOvernight">First Overnight</option>
163                         <option value="expressSaver">Express Saver</option>
164                         <option value="ground">Ground</option>
165                 </optgroup>
166                 <optgroup label="US Mail">
167                         <option value="standard">Standard: 7 day</option>
168                         <option value="rush">Rush: 3 days</option>
169                         <option value="express">Express: next day (disabled)</option>
170                         <option value="overnight">Overnight</option>
171                 </optgroup>
172         </select>
173 </div>
174 -->
175
176
177 <h2>Vertically grouped select inputs</h2>
178
179 <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>
180
181 <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>
182
183 <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>
184                         
185 <pre><code>     
186 &lt;div data-role=&quot;fieldcontain&quot;&gt;
187 &lt;fieldset data-role=&quot;controlgroup&quot;&gt;
188         &lt;legend&gt;Date of Birth:&lt;/legend&gt;
189
190     &lt;label for="select-choice-month">Month&lt;/label&gt;
191 &lt;select name="select-choice-month" id="select-choice-month"&gt;
192         &lt;option&gt;Month&lt;/option&gt;
193         &lt;option value="jan"&gt;January&lt;/option&gt;
194         &lt;!-- etc. --&gt;
195 &lt;/select&gt;
196
197         &lt;label for="select-choice-day">Day&lt;/label&gt;
198 &lt;select name="select-choice-day" id="select-choice-day"&gt;
199         &lt;option&gt;Day&lt;/option&gt;
200         &lt;option value="1"&gt;1&lt;/option&gt;
201         &lt;!-- etc. --&gt;
202 &lt;/select&gt;
203
204 &lt;label for="select-choice-year">Year&lt;/label&gt;
205 &lt;select name="select-choice-year" id="select-choice-year"&gt;
206         &lt;option&gt;Year&lt;/option&gt;
207         &lt;option value="2011"&gt;2011&lt;/option&gt;
208         &lt;!-- etc. --&gt;
209 &lt;/select&gt;
210 &lt;/fieldset&gt;
211 &lt;/div&gt;
212 </code></pre>
213
214         <div data-role="fieldcontain">
215         <fieldset data-role="controlgroup">
216                 <legend>Date of Birth:</legend>
217                 
218                 <label for="select-choice-month">Month</label>
219                 <select name="select-choice-month" id="select-choice-month">
220                         <option>Month</option>
221                         <option value="jan">January</option>
222                         <option value="dec">December</option>
223                         <option value="feb">February</option>
224                         <option value="mar">March</option>
225                         <option value="apr">April</option>
226                         <option value="may">May</option>
227                         <option value="jun">June</option>
228                         <option value="jul">July</option>
229                         <option value="aug">August</option>
230                         <option value="sep">September</option>
231                         <option value="oct">October</option>
232                         <option value="nov">November</option>
233                         <option value="dec">December</option>
234                 </select>
235
236                 <label for="select-choice-day">Day</label>
237                 <select name="select-choice-day" id="select-choice-day">
238                         <option>Day</option>
239                         <option value="1">1</option>
240                         <option value="2">2</option>
241                         <option value="3">3</option>
242                         <option value="4">4</option>
243                         <option value="5">5</option>
244                         <option value="6">6</option>
245                         <option value="7">7</option>
246                 </select>
247
248                 <label for="select-choice-year">Year</label>
249                 <select name="select-choice-year" id="select-choice-year">
250                         <option>Year</option>
251                         <option value="2011">2011</option>
252                         <option value="2010">2010</option>
253                         <option value="2009">2009</option>
254                         <option value="2008">2008</option>
255                         <option value="2007">2007</option>
256                         <option value="2006">2006</option>
257                         <option value="2005">2005</option>
258                         <option value="2004">2004</option>
259                 </select>
260         </fieldset>
261
262 </div>
263
264 <h2>Horizontally grouped select inputs</h2>
265 <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>
266
267 <code>
268 &lt;fieldset data-role="controlgroup" <strong>data-type="horizontal"</strong>&gt;
269 </code>
270
271         <fieldset data-role="controlgroup" data-type="horizontal">
272                 <legend>Date of Birth:</legend>
273                 
274                 <label for="select-choice-month">Month</label>
275                 <select name="select-choice-month" id="select-choice-month">
276                         <option>Month</option>
277                         <option value="jan">January</option>
278                         <option value="dec">December</option>
279                         <option value="feb">February</option>
280                         <option value="mar">March</option>
281                         <option value="apr">April</option>
282                         <option value="may">May</option>
283                         <option value="jun">June</option>
284                         <option value="jul">July</option>
285                         <option value="aug">August</option>
286                         <option value="sep">September</option>
287                         <option value="oct">October</option>
288                         <option value="nov">November</option>
289                         <option value="dec">December</option>
290                 </select>
291
292                 <label for="select-choice-day">Day</label>
293                 <select name="select-choice-day" id="select-choice-day">
294                         <option>Day</option>
295                         <option value="1">1</option>
296                         <option value="2">2</option>
297                         <option value="3">3</option>
298                         <option value="4">4</option>
299                         <option value="5">5</option>
300                         <option value="6">6</option>
301                         <option value="7">7</option>
302                 </select>
303
304                 <label for="select-choice-year">Year</label>
305                 <select name="select-choice-year" id="select-choice-year">
306                         <option>Year</option>
307                         <option value="2011">2011</option>
308                         <option value="2010">2010</option>
309                         <option value="2009">2009</option>
310                         <option value="2008">2008</option>
311                         <option value="2007">2007</option>
312                         <option value="2006">2006</option>
313                         <option value="2005">2005</option>
314                         <option value="2004">2004</option>
315                 </select>
316         </fieldset>
317         
318 <h2>Calling the select menu plugin</h2>
319 <p>The select menu plugin will auto initialize on any page that contains a select menu, no 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>
320 <pre><code>
321 $('select').selectmenu();                       
322 </code></pre>
323     
324         </form>
325         
326         
327         <h2>Theming selects</h2>
328         <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>
329
330         <div data-role="fieldcontain">
331                 <label for="select-choice-11" class="select">Actions</label>
332                 <select name="select-choice-11" id="select-choice-11" data-theme="e" data-icon="gear" data-inline="true" data-native-menu="false">
333                         <option value="edit">Edit user</option>
334                         <option value="delete">Delete user</option>
335                 </select>
336         </div>
337     
338         <p>The <code>data-overlay-theme</code> attribute can be added a select element to set the color of the overlay layer that the dialog-based custom select menus and the outer border of the smaller custom menus. By default, the content block colors for swatch A will be used for the overlays.</p>
339       
340         <div data-role="fieldcontain">
341                 <label for="select-choice-15" class="select">Size</label>
342                 <select name="select-choice-15" id="select-choice-15" data-theme="b" data-overlay-theme="d" data-native-menu="false">
343                         <option value="t">Tall</option>
344                         <option value="g">Grande</option>
345                         <option value="v">Vente</option>
346                 </select>
347         </div>
348         
349         <div data-role="fieldcontain">
350                 <label for="select-choice-13" class="select">Choose state(s):</label>
351                 <select name="select-choice-13" id="select-choice-13" data-native-menu="false" data-theme="a" data-overlay-theme="e">
352                         <option>Choose options</option>
353                         <option value="AL">Alabama</option>
354                         <option value="AK">Alaska</option>
355                         <option value="AZ">Arizona</option>
356                         <option value="AR">Arkansas</option>
357                         <option value="CA">California</option>
358                         <option value="CO">Colorado</option>
359                         <option value="CT">Connecticut</option>
360                         <option value="DE">Delaware</option>
361                         <option value="FL">Florida</option>
362                         <option value="GA">Georgia</option>
363                         <option value="HI">Hawaii</option>
364                         <option value="ID">Idaho</option>
365                         <option value="IL">Illinois</option>
366                         <option value="IN">Indiana</option>
367                         <option value="IA">Iowa</option>
368                         <option value="KS">Kansas</option>
369                         <option value="KY">Kentucky</option>
370                         <option value="LA">Louisiana</option>
371                         <option value="ME">Maine</option>
372                         <option value="MD">Maryland</option>
373                         <option value="MA">Massachusetts</option>
374                         <option value="MI">Michigan</option>
375                         <option value="MN">Minnesota</option>
376                         <option value="MS">Mississippi</option>
377                         <option value="MO">Missouri</option>
378                         <option value="MT">Montana</option>
379                         <option value="NE">Nebraska</option>
380                         <option value="NV">Nevada</option>
381                         <option value="NH">New Hampshire</option>
382                         <option value="NJ">New Jersey</option>
383                         <option value="NM">New Mexico</option>
384                         <option value="NY">New York</option>
385                         <option value="NC">North Carolina</option>
386                         <option value="ND">North Dakota</option>
387                         <option value="OH">Ohio</option>
388                         <option value="OK">Oklahoma</option>
389                         <option value="OR">Oregon</option>
390                         <option value="PA">Pennsylvania</option>
391                         <option value="RI">Rhode Island</option>
392                         <option value="SC">South Carolina</option>
393                         <option value="SD">South Dakota</option>
394                         <option value="TN">Tennessee</option>
395                         <option value="TX">Texas</option>
396                         <option value="UT">Utah</option>
397                         <option value="VT">Vermont</option>
398                         <option value="VA">Virginia</option>
399                         <option value="WA">Washington</option>
400                         <option value="WV">West Virginia</option>
401                         <option value="WI">Wisconsin</option>
402                         <option value="WY">Wyoming</option>
403                 </select>
404         </div>
405         
406         <h2>Custom select menus</h2>
407         <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.
408                 
409         <a href="custom.html" data-role="button">Custom select menu docs</a>
410                 </p>
411         
412         </div><!--/content-primary -->          
413         
414         <div class="content-secondary">
415                 
416                 <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
417                         
418                                 <h3>More in this section</h3>
419                                 
420                                 <ul data-role="listview" data-theme="c" data-dividertheme="d">
421                                 
422                                         <li data-role="list-divider">Form elements</li>
423                                         <li><a href="../docs-forms.html">Form basics</a></li>
424                                         <li><a href="../forms-all.html">Form element gallery</a></li>
425                                         <li><a href="../textinputs/index.html">Text inputs</a></li>
426                                         <li><a href="../search/">Search input</a></li>
427                                         <li><a href="../slider/">Slider</a></li>
428                                         <li><a href="../switch/">Flip toggle switch</a></li>
429                                         <li><a href="../radiobuttons/">Radio buttons</a></li>
430                                         <li><a href="../checkboxes/">Checkboxes</a></li>
431                                         <li data-theme="a"><a href="index.html">Select menus</a></li>
432                                         <li><a href="../forms-themes.html">Theming forms</a></li>
433                                         <li><a href="../forms-all-native.html">Native form elements</a></li>
434                                         <li><a href="../forms-sample.html">Submitting forms</a></li>
435                                         
436         
437                                 </ul>
438                 </div>
439         </div>          
440
441 </div><!-- /content -->
442
443 <div data-role="footer" class="footer-docs" data-theme="c">
444                 <p>&copy; 2011 The jQuery Project</p>
445 </div>
446         
447 </div><!-- /page -->
448
449 </body>
450 </html>
451