2.0_beta sync to rsa
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.1.0 / docs / forms / switch / 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 - Switch</title>
7         <link rel="stylesheet"  href="../../../css/themes/default/jquery.mobile.css" />
8         <link rel="stylesheet" href="../../_assets/css/jqm-docs.css"/>
9         <script src="../../../experiments/themeswitcher/jquery.mobile.themeswitcher.js"></script>
10         <script src="../../../js/jquery.js"></script>
11         <script src="../../../docs/_assets/js/jqm-docs.js"></script>
12         <script src="../../../js/"></script>
13
14 </head>
15 <body>
16
17         <div data-role="page" class="type-interior">
18
19                 <div data-role="header" data-theme="f">
20                 <h1>Flip Toggle Switch</h1>
21                 <a href="../../../" data-icon="home" data-iconpos="notext" data-direction="reverse">Home</a>
22                 <a href="../../nav.html" data-icon="search" data-iconpos="notext" data-rel="dialog" data-transition="fade">Search</a>
23         </div><!-- /header -->
24
25         <div data-role="content">
26                 <div class="content-primary">
27
28                 <form action="#" method="get">
29                         <h2>Flip toggle switch</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>A binary "flip" switch is a common UI element on mobile devices that is used for binary on/off or true/false data input. You can either drag the flip handle like a slider or tap one side of the switch.</p>
39                         
40                         <p>To create a flip toggle, start with a <code>select</code> with two options. The first option will be styled as the "on" state switch and the second will be styled as the "off" state so write your options accordingly. View the <a href="../../api/data-attributes.html">data- attribute reference</a> to see all the possible attributes you can add to flip switches.</p>
41                                 
42                         <p>Set the <code>for</code> attribute of the <code>label</code> to match the ID of the <code>input</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 <pre><code>     
45 &lt;label for=&quot;flip-a&quot;&gt;Select slider:&lt;/label&gt;
46 &lt;select name=&quot;slider&quot; id=&quot;flip-a&quot; data-role=&quot;slider&quot;&gt;
47         &lt;option value=&quot;off&quot;&gt;Off&lt;/option&gt;
48         &lt;option value=&quot;on&quot;&gt;On&lt;/option&gt;
49 &lt;/select&gt; 
50 </code></pre>   
51
52                         <p>This will produce a basic flip toggle switch input. The default styles set the width of the switch to 100% of the parent container and stack the label on a separate line.</p>
53
54                         <label for="flip-a">Flip switch:</label>
55                         <select name="slider" id="flip-a" data-role="slider">
56                                 <option value="off">Off</option>
57                                 <option value="on">On</option>
58                         </select> 
59                         
60                         
61                         <h2>Longer Labels</h2>
62                         <p>The control is proportionally scaled, so to use longer labels one can just add a line of CSS setting the switch to the desired width. For example, given the following markup:</p>
63 <pre><code>
64 &lt;div class="containing-element"&gt;
65         &lt;label for="flip-min">Flip switch:&lt;/label&gt;
66         &lt;select name="slider" id="flip-min" data-role="slider"&gt;
67                 &lt;option value="off">Switch Off&lt;/option&gt;
68                 &lt;option value="on">Switch On&lt;/option&gt;
69         &lt;/select&gt;
70 &lt;/div&gt;
71 </code></pre>
72         
73                         <p><code>.containing-element .ui-slider-switch { width: 9em }</code> will produce:</p>
74                 
75                         <style type="text/css" media="screen">
76                         .containing-element .ui-slider-switch { width: 9em; }
77                         </style>
78                         
79                         <div class="containing-element">
80                                 <label for="flip-min">Flip switch:</label>
81                                 <select name="slider" id="flip-min" data-role="slider">
82                                         <option value="off">Switch Off</option>
83                                         <option value="on">Switch On</option>
84                                 </select> 
85                         </div>
86                         
87                         <p>As some default styles hinge on fieldcontains, note that you may have to ensure that custom styles apply to switches within fieldcontains by using <code>.ui-field-contain div.ui-slider-switch { width: […]; }</code>.</p>
88                         
89                         <h2>Mini version</h2>
90
91                         <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>
92
93 <pre><code>     
94 &lt;label for=&quot;flip-a&quot;&gt;Select slider:&lt;/label&gt;
95 &lt;select name=&quot;slider&quot; id=&quot;flip-a&quot; data-role=&quot;slider&quot; <strong>data-mini=&quot;true&quot;</strong>&gt;
96         &lt;option value=&quot;off&quot;&gt;Off&lt;/option&gt;
97         &lt;option value=&quot;on&quot;&gt;On&lt;/option&gt;
98 &lt;/select&gt;
99 </code></pre>
100                         
101                         <p>This will produce a flip switch that is not as tall as the standard version and has a smaller text size.</p>
102                         <label for="flip-min">Flip switch:</label>
103                         <select name="slider" id="flip-min" data-role="slider" data-mini="true">
104                                 <option value="off">Off</option>
105                                 <option value="on">On</option>
106                         </select>
107                         
108
109                         <h2>Field containers</h2>
110                          <p>Optionally wrap the switch markup in a container with the <code>data-role="fieldcontain"</code> attribute to help visually group it in a longer form.</p>
111
112 <pre><code>     
113 <strong>&lt;div data-role=&quot;fieldcontain&quot;&gt;
114 </strong>&lt;label for=&quot;flip-b&quot;&gt;Flip switch:&lt;/label&gt;
115         &lt;select name=&quot;slider&quot; id=&quot;flip-b&quot; data-role=&quot;slider&quot;&gt;
116                 &lt;option value=&quot;no&quot;&gt;No&lt;/option&gt;
117                 &lt;option value=&quot;yes&quot;&gt;Yes&lt;/option&gt;
118         &lt;/select&gt; 
119 <strong>&lt;/div&gt;
120 </strong></code></pre>  
121                 <p>The flip toggle switch is now displayed like this:</p>
122                 <div data-role="fieldcontain">
123                         <label for="flip-b">Flip switch:</label>
124                         <select name="slider" id="flip-b" data-role="slider">
125                                 <option value="nope">Nope</option>
126                                 <option value="yep">Yep</option>
127                         </select> 
128                 </div>
129                                                 
130                                 
131                 <h2>Theming the flip switch</h2>        
132                 
133                 <p>Like all form elements, this widget will automatically inherit the theme from its parent container. To choose a specific theme color swatch, specify the <code>data-theme</code> attribute on the select and specify a swatch letter.</p>    
134                 
135 <pre><code>     
136 &lt;div data-role=&quot;fieldcontain&quot;&gt;
137         &lt;label for=&quot;flip-c&quot;&gt;Flip switch:&lt;/label&gt;
138         &lt;select name=&quot;slider&quot; id=&quot;flip-c&quot; data-role=&quot;slider&quot; data-theme=&quot;a&quot;&gt;
139                 &lt;option value=&quot;no&quot;&gt;No&lt;/option&gt;
140                 &lt;option value=&quot;yes&quot;&gt;Yes&lt;/option&gt;
141         &lt;/select&gt; 
142 &lt;/div&gt;
143 </code></pre>   
144                                 <p>This results in a switch with the A swatch colors for the handle. Note that the lefthand "on" state gets the active state color.</p>
145                                 <div data-role="fieldcontain">
146                                         <label for="flip-c">Flip switch:</label>
147                                         <select name="slider" id="flip-c" data-role="slider" data-theme="a">
148                                                 <option value="hate">Hate</option>
149                                                 <option value="love">Love</option>
150                                         </select> 
151                                 </div>
152                                 
153                                 <p>Here is a E swatch variation:</p>
154                                 <div data-role="fieldcontain">
155                                         <label for="flip-d">Flip switch:</label>
156                                         <select name="slider" id="flip-d" data-role="slider" data-theme="e">
157                                                 <option value="no">No</option>
158                                                 <option value="yes">Yes</option>
159                                         </select> 
160                                 </div>
161                 
162                 <h2>Calling the switch plugin</h2>
163
164 <p>This plugin will auto-initialize on any page that contains a <code>select</code> with the <code>data-role="slider"</code> attribute. However, if needed you can directly call the <code>slider</code> plugin on any selector, just like any jQuery plugin:</p>
165 <pre><code>
166 $('select').slider();                   
167 </code></pre>
168     
169                 </form>
170         </div><!--/content-primary -->          
171         
172         <div class="content-secondary">
173                 
174                 <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
175                         
176                                 <h3>More in this section</h3>
177                                 
178                                 <ul data-role="listview" data-theme="c" data-dividertheme="d">
179                                 
180                                         <li data-role="list-divider">Form elements</li>
181                                         <li><a href="../docs-forms.html">Form basics</a></li>
182                                         <li><a href="../forms-all.html">Form element gallery</a></li>
183                                         <li><a href="../forms-all-mini.html">Mini form element gallery</a></li>
184                                         <li><a href="../textinputs/index.html">Text inputs</a></li>
185                                         <li><a href="../search/">Search input</a></li>
186                                         <li><a href="../slider/">Slider</a></li>
187                                         <li data-theme="a"><a href="index.html">Flip toggle switch</a></li>
188                                         <li><a href="../radiobuttons/">Radio buttons</a></li>
189                                         <li><a href="../checkboxes/">Checkboxes</a></li>
190                                         <li><a href="../selects/">Select menus</a></li>
191                                         <li><a href="../forms-themes.html">Theming forms</a></li>
192                                         <li><a href="../forms-all-native.html">Native form elements</a></li>
193                                         <li><a href="../forms-sample.html">Submitting forms</a></li>
194                                         
195         
196                                 </ul>
197                 </div>
198         </div>          
199
200 </div><!-- /content -->
201
202 <div data-role="footer" class="footer-docs" data-theme="c">
203                 <p>&copy; 2011-12 The jQuery Foundation</p>
204 </div>
205         
206 </div><!-- /page -->
207
208 </body>
209 </html>
210