Tizen 2.1 base
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / docs / forms / selects / custom.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 <h2>Select menus</h2>
27
28 <ul data-role="controlgroup" data-type="horizontal" class="localnav">
29         <li><a href="index.html" data-role="button" data-transition="fade">Basics</a></li>
30         <li><a href="options.html" data-role="button" data-transition="fade">Options</a></li>
31         <li><a href="methods.html" data-role="button" data-transition="fade">Methods</a></li>
32         <li><a href="events.html" data-role="button" data-transition="fade">Events</a></li>
33 </ul>
34
35 <h2>Custom select menus</h2>
36 <p>The framework is capable of building a custom menu based on the <code>select</code> element's list of options.  We recommend using a custom menu when multiple selections are required, or when the menu itself must be styled with CSS.</p>
37
38 <p>You can optionally use custom-styled select menus 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 (all explained below).  In addition, the framework applies the custom button's theme to the menu to better match the look and feel and provide visual consistency across platforms. Lastly, custom menus often look better on desktop browsers because native desktop menus are smaller than their mobile counterparts and tend to look disproportionate.</p>
39
40         <p>Keep in mind that there is overhead involved in parsing the native select to build a custom menu. If there are a lot of selects on a page, or a select has a long list of options, this can impact the performance of the page, so we recommend using custom menus sparingly. </p>
41         
42         <p>To use custom menus on a specific <code>select</code>, just add the <code>data-native-menu="false"</code> attribute. Alternately, this can also programmatically set the select menu's <code>nativeMenu</code> configuration option to <code>false</code> in a callback bound to the <code>mobileinit</code> event to achieve the same effect. This will globally make all selects use the custom menu by default. The following must be included in the page after jQuery is loaded but before jQuery Mobile is loaded.</p>
43         
44
45 <code>
46 <pre>
47 $(document).bind('mobileinit',function(){
48    $.mobile.selectmenu.prototype.options.nativeMenu = false;
49 });
50 </pre>
51 </code>
52
53                         <p>When the <code>select</code> has a small number of options that will fit on the device's screen, the menu will appear as a small overlay with a pop transition:</p>
54
55                         <div data-role="fieldcontain">
56                                 <label for="select-choice-custom" class="select">Shipping method:</label>
57                                 <select name="select-choice-1" id="select-choice-custom" data-native-menu="false">
58                                         <option value="standard">Standard: 7 day</option>
59                                         <option value="rush">Rush: 3 days</option>
60                                         <option value="express">Express: next day</option>
61                                         <option value="overnight">Overnight</option>
62                                 </select>
63                         </div>
64
65                         <p>When it has too many options to show on the device's screen, the framework will automatically create a new &quot;page&quot; populated with a standard <a href="../../lists/docs-lists.html">list view</a> for the options. This allows us to use the native scrolling included on the device for moving through a long list. The text inside the <code>label</code> is used as the title for this page.</p>
66
67
68                                         <div data-role="fieldcontain">
69                                                 <label for="select-choice-3" class="select">Your state:</label>
70                                                 <select name="select-choice-3" id="select-choice-3" data-native-menu="false">
71                                                         <option value="AL">Alabama</option>
72                                                         <option value="AK">Alaska</option>
73                                                         <option value="AZ">Arizona</option>
74                                                         <option value="AR">Arkansas</option>
75                                                         <option value="CA">California</option>
76                                                         <option value="CO">Colorado</option>
77                                                         <option value="CT">Connecticut</option>
78                                                         <option value="DE">Delaware</option>
79                                                         <option value="FL">Florida</option>
80                                                         <option value="GA">Georgia</option>
81                                                         <option value="HI">Hawaii</option>
82                                                         <option value="ID">Idaho</option>
83                                                         <option value="IL">Illinois</option>
84                                                         <option value="IN">Indiana</option>
85                                                         <option value="IA">Iowa</option>
86                                                         <option value="KS">Kansas</option>
87                                                         <option value="KY">Kentucky</option>
88                                                         <option value="LA">Louisiana</option>
89                                                         <option value="ME">Maine</option>
90                                                         <option value="MD">Maryland</option>
91                                                         <option value="MA">Massachusetts</option>
92                                                         <option value="MI">Michigan</option>
93                                                         <option value="MN">Minnesota</option>
94                                                         <option value="MS">Mississippi</option>
95                                                         <option value="MO">Missouri</option>
96                                                         <option value="MT">Montana</option>
97                                                         <option value="NE">Nebraska</option>
98                                                         <option value="NV">Nevada</option>
99                                                         <option value="NH">New Hampshire</option>
100                                                         <option value="NJ">New Jersey</option>
101                                                         <option value="NM">New Mexico</option>
102                                                         <option value="NY">New York</option>
103                                                         <option value="NC">North Carolina</option>
104                                                         <option value="ND">North Dakota</option>
105                                                         <option value="OH">Ohio</option>
106                                                         <option value="OK">Oklahoma</option>
107                                                         <option value="OR">Oregon</option>
108                                                         <option value="PA">Pennsylvania</option>
109                                                         <option value="RI">Rhode Island</option>
110                                                         <option value="SC">South Carolina</option>
111                                                         <option value="SD">South Dakota</option>
112                                                         <option value="TN">Tennessee</option>
113                                                         <option value="TX">Texas</option>
114                                                         <option value="UT">Utah</option>
115                                                         <option value="VT">Vermont</option>
116                                                         <option value="VA">Virginia</option>
117                                                         <option value="WA">Washington</option>
118                                                         <option value="WV">West Virginia</option>
119                                                         <option value="WI">Wisconsin</option>
120                                                         <option value="WY">Wyoming</option>
121                                                 </select>
122                                         </div>
123
124         <h3>Disabled options</h3>
125         <p>jQuery Mobile will automatically disable and style option tags with the <code>disabled</code> attribute.  In the demo below, the second option &quot;Rush: 3 days&quot; has been set to disabled.</p>
126
127         <div data-role="fieldcontain">
128                 <label for="select-choice-7" class="select">Shipping method:</label>
129                 <select name="select-choice-7" id="select-choice-7">
130                         <option value="standard">Standard: 7 day</option>
131                         <option value="rush" disabled="disabled">Rush: 3 days</option>
132                         <option value="express">Express: next day</option>
133                         <option value="overnight">Overnight</option>
134                 </select>
135         </div>
136         
137         <h3>Placeholder options</h3>
138         <p>It's common for developers to include a &quot;null&quot; option in their select element to force a user to choose an option. If a placeholder option is present in your markup, jQuery Mobile will hide them in the overlay menu, showing only valid choices to the user, and display the placeholder text inside the menu as a header.  A placeholder option is added when the framework finds:</p>
139         <ul>
140                 <li>An option with no value attribute (or an empty value attribute)</li>
141                 <li>An option with no text node</li>
142                 <li>An option with a <code>data-placeholder="true"</code> attribute. (This allows you to use an option that has a value and a textnode as a placeholder option).</li>
143         </ul>
144
145         <p>You can disable this feature through the selectmenu plugin's <code>hidePlaceholderMenuItems</code> option, like this:</p>
146         <pre>
147         <code>
148 $.mobile.selectmenu.prototype.options.hidePlaceholderMenuItems = false;
149         </code>
150         </pre>
151
152         <p>Examples of various placeholder options:</p>
153
154
155         <div data-role="fieldcontain">
156                 <label for="select-choice-4" class="select">Shipping method:</label>
157                 <select name="select-choice-4" id="select-choice-4" data-native-menu="false">
158                         <option></option>
159                         <option value="standard">Standard: 7 day</option>
160                         <option value="rush">Rush: 3 days</option>
161                         <option value="express">Express: next day</option>
162                         <option value="overnight">Overnight</option>
163                 </select>
164         </div>
165
166
167         <div data-role="fieldcontain">
168                 <label for="select-choice-5" class="select">Shipping method:</label>
169                 <select name="select-choice-5" id="select-choice-5" data-native-menu="false">
170                         <option>Choose one...</option>
171                         <option value="standard">Standard: 7 day</option>
172                         <option value="rush">Rush: 3 days</option>
173                         <option value="express">Express: next day</option>
174                         <option value="overnight">Overnight</option>
175                 </select>
176         </div>
177
178
179         <div data-role="fieldcontain">
180                 <label for="select-choice-6" class="select">Shipping method:</label>
181                 <select name="select-choice-6" id="select-choice-6" data-native-menu="false">
182                         <option value="choose-one" data-placeholder="true">Choose one...</option>
183                         <option value="standard">Standard: 7 day</option>
184                         <option value="rush">Rush: 3 days</option>
185                         <option value="express">Express: next day</option>
186                         <option value="overnight">Overnight</option>
187                 </select>
188         </div>
189
190
191         <h3>Multiple selects</h3>       
192         <p>If the <code>multiple</code> attribute is present in your markup, jQuery Mobile will enhance the element with a few extra considerations:</p>
193
194         <ul>
195         <li>A header element will be created inside the menu and display the placeholder text and a close button.</li>
196         <li>Clicking on an item inside the overlay menu will not close the widget.</li>
197         <li>A ghosted, unchecked icon will appear adjacent to each unselected item.  When the item is selected the icon will change to a checkbox.  Neither icon will appear inside a single select box.</li>
198         <li>Once 2+ items are selected, a counter element with the total number of selected items will appear inside the button.</li>
199         <li>The text of each selected item will appear inside the button as a list.  If the button is not wide enough to display the entire list, it is truncated with an ellipses.</li>
200         <li>If no items are selected, the button's text will default to the placeholder text.</li>
201         <li>If no placeholder element exists, the default button text will be blank and the header will appear with just a close button. Because this isn't a friendly user experience, we recommended that you always specify a placeholder element when using multiple select boxes.</li>
202         </ul>
203
204         <div data-role="fieldcontain">
205                 <label for="select-choice-9" class="select">Shipping method(s):</label>
206                 <select name="select-choice-9" id="select-choice-9" multiple="multiple" data-native-menu="false">
207                         <option>Choose options</option>
208                         <option value="standard">Standard: 7 day</option>
209                         <option value="rush">Rush: 3 days</option>
210                         <option value="express">Express: next day</option>
211                         <option value="overnight">Overnight</option>
212                 </select>
213         </div>
214
215         <p>When a select is large enough to where the menu will open in a new page, the placeholder text is displayed in the button when no items are selected, and the <code>label</code> text is displayed in the menu's header.  This differs from smaller overlay menus where the placeholder text is displayed in both the button and the header, and from full-page single selects where the placeholder text is not used at all.</p>
216
217         <div data-role="fieldcontain">
218                 <label for="select-choice-10" class="select">Choose state(s):</label>
219                 <select name="select-choice-10" id="select-choice-10" multiple="multiple" data-native-menu="false">
220                         <option>Choose options</option>
221                         <option value="AL">Alabama</option>
222                         <option value="AK">Alaska</option>
223                         <option value="AZ">Arizona</option>
224                         <option value="AR">Arkansas</option>
225                         <option value="CA">California</option>
226                         <option value="CO">Colorado</option>
227                         <option value="CT">Connecticut</option>
228                         <option value="DE">Delaware</option>
229                         <option value="FL">Florida</option>
230                         <option value="GA">Georgia</option>
231                         <option value="HI">Hawaii</option>
232                         <option value="ID">Idaho</option>
233                         <option value="IL">Illinois</option>
234                         <option value="IN">Indiana</option>
235                         <option value="IA">Iowa</option>
236                         <option value="KS">Kansas</option>
237                         <option value="KY">Kentucky</option>
238                         <option value="LA">Louisiana</option>
239                         <option value="ME">Maine</option>
240                         <option value="MD">Maryland</option>
241                         <option value="MA">Massachusetts</option>
242                         <option value="MI">Michigan</option>
243                         <option value="MN">Minnesota</option>
244                         <option value="MS">Mississippi</option>
245                         <option value="MO">Missouri</option>
246                         <option value="MT">Montana</option>
247                         <option value="NE">Nebraska</option>
248                         <option value="NV">Nevada</option>
249                         <option value="NH">New Hampshire</option>
250                         <option value="NJ">New Jersey</option>
251                         <option value="NM">New Mexico</option>
252                         <option value="NY">New York</option>
253                         <option value="NC">North Carolina</option>
254                         <option value="ND">North Dakota</option>
255                         <option value="OH">Ohio</option>
256                         <option value="OK">Oklahoma</option>
257                         <option value="OR">Oregon</option>
258                         <option value="PA">Pennsylvania</option>
259                         <option value="RI">Rhode Island</option>
260                         <option value="SC">South Carolina</option>
261                         <option value="SD">South Dakota</option>
262                         <option value="TN">Tennessee</option>
263                         <option value="TX">Texas</option>
264                         <option value="UT">Utah</option>
265                         <option value="VT">Vermont</option>
266                         <option value="VA">Virginia</option>
267                         <option value="WA">Washington</option>
268                         <option value="WV">West Virginia</option>
269                         <option value="WI">Wisconsin</option>
270                         <option value="WY">Wyoming</option>
271                 </select>
272         </div>
273
274
275
276         
277
278         <h3>Optgroup support</h3>
279         <p>If a select menu contains <code>optgroup</code> elements, jQuery Mobile will create a divider &amp; group items based on the <code>label</code> attribute's text:</p>
280
281         <div data-role="fieldcontain">
282                 <label for="select-choice-8" class="select">Shipping method:</label>
283                 <select name="select-choice-8" id="select-choice-8" data-native-menu="false">
284                         <optgroup label="USPS">
285                                 <option value="standard">Standard: 7 day</option>
286                                 <option value="rush">Rush: 3 days</option>
287                                 <option value="express">Express: next day</option>
288                                 <option value="overnight">Overnight</option>
289                         </optgroup>
290                         <optgroup label="FedEx">
291                                 <option value="firstOvernight">First Overnight</option>
292                                 <option value="expressSaver">Express Saver</option>
293                                 <option value="ground">Ground</option>
294                         </optgroup>
295                 </select>
296         </div>
297
298
299         
300         
301         
302         </div><!--/content-primary -->          
303         
304         <div class="content-secondary">
305                 
306                 <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
307                         
308                                 <h3>More in this section</h3>
309                                 
310                                 <ul data-role="listview" data-theme="c" data-dividertheme="d">
311                                 
312                                         <li data-role="list-divider">Form elements</li>
313                                         <li><a href="../docs-forms.html">Form basics</a></li>
314                                         <li><a href="../forms-all.html">Form element gallery</a></li>
315                                         <li><a href="../textinputs/index.html">Text inputs</a></li>
316                                         <li><a href="../search/">Search input</a></li>
317                                         <li><a href="../slider/">Slider</a></li>
318                                         <li><a href="../switch/">Flip toggle switch</a></li>
319                                         <li><a href="../radiobuttons/">Radio buttons</a></li>
320                                         <li><a href="../checkboxes/">Checkboxes</a></li>
321                                         <li data-theme="a"><a href="index.html">Select menus</a></li>
322                                         <li><a href="../forms-themes.html">Theming forms</a></li>
323                                         <li><a href="../forms-all-native.html">Native form elements</a></li>
324                                         <li><a href="../forms-sample.html">Submitting forms</a></li>
325                                         
326         
327                                 </ul>
328                 </div>
329         </div>          
330
331 </div><!-- /content -->
332
333 <div data-role="footer" class="footer-docs" data-theme="c">
334                 <p>&copy; 2011 The jQuery Project</p>
335 </div>
336         
337 </div><!-- /page -->
338
339 </body>
340 </html>
341