index.html 19 KB

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