d3a111e10921e2c7d110786b4aa3c14cfcdedea0
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / 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 - Sliders</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>Flip Toggle Switch</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                         <h2>Flip toggle switch</h2>
28                         
29                         <ul data-role="controlgroup" data-type="horizontal" class="localnav">
30                                 <li><a href="index.html" data-role="button" data-transition="fade" class="ui-btn-active">Basics</a></li>
31                                 <li><a href="options.html" data-role="button" data-transition="fade">Options</a></li>
32                                 <li><a href="methods.html" data-role="button" data-transition="fade">Methods</a></li>
33                                 <li><a href="events.html" data-role="button" data-transition="fade">Events</a></li>
34                         </ul>
35     
36                         <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>
37                         
38                                 <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>
39                                 
40                                 <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>
41                                 
42 <pre><code>     
43 &lt;label for=&quot;flip-a&quot;&gt;Select slider:&lt;/label&gt;
44 &lt;select name=&quot;slider&quot; id=&quot;flip-a&quot; data-role=&quot;slider&quot;&gt;
45         &lt;option value=&quot;off&quot;&gt;Off&lt;/option&gt;
46         &lt;option value=&quot;on&quot;&gt;On&lt;/option&gt;
47 &lt;/select&gt; 
48 </code></pre>   
49
50                         <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 stacks the label on a separate line.</p>
51
52                         <label for="flip-a">Flip switch:</label>
53                         <select name="slider" id="flip-a" data-role="slider">
54                                 <option value="off">Off</option>
55                                 <option value="on">On</option>
56                         </select> 
57                                 
58                          <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>
59
60 <pre><code>     
61 <strong>&lt;div data-role=&quot;fieldcontain&quot;&gt;
62 </strong>&lt;label for=&quot;flip-b&quot;&gt;Flip switch:&lt;/label&gt;
63         &lt;select name=&quot;slider&quot; id=&quot;flip-b&quot; data-role=&quot;slider&quot;&gt;
64                 &lt;option value=&quot;no&quot;&gt;No&lt;/option&gt;
65                 &lt;option value=&quot;yes&quot;&gt;Yes&lt;/option&gt;
66         &lt;/select&gt; 
67 <strong>&lt;/div&gt;
68 </strong></code></pre>  
69                 <p>The flip toggle switch is now displayed like this:</p>
70                 <div data-role="fieldcontain">
71                         <label for="flip-b">Flip switch:</label>
72                         <select name="slider" id="flip-b" data-role="slider">
73                                 <option value="no">No</option>
74                                 <option value="yes">Yes</option>
75                         </select> 
76                 </div>
77                                                 
78                                 
79                 <h2>Theming the flip switch</h2>        
80                 
81                 <p>Like all form elements, this widget will automatically inherit the theme from it's 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>   
82                 
83 <pre><code>     
84 &lt;div data-role=&quot;fieldcontain&quot;&gt;
85         &lt;label for=&quot;flip-c&quot;&gt;Flip switch:&lt;/label&gt;
86         &lt;select name=&quot;slider&quot; id=&quot;flip-c&quot; data-role=&quot;slider&quot; data-theme=&quot;a&quot;&gt;
87                 &lt;option value=&quot;no&quot;&gt;No&lt;/option&gt;
88                 &lt;option value=&quot;yes&quot;&gt;Yes&lt;/option&gt;
89         &lt;/select&gt; 
90 &lt;/div&gt;
91 </code></pre>   
92                                 <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>
93                                 <div data-role="fieldcontain">
94                                         <label for="flip-c">Flip switch:</label>
95                                         <select name="slider" id="flip-c" data-role="slider" data-theme="a">
96                                                 <option value="no">No</option>
97                                                 <option value="yes">Yes</option>
98                                         </select> 
99                                 </div>
100                                 
101                                 <p>Here is a E swatch variation:</p>
102                                 <div data-role="fieldcontain">
103                                         <label for="flip-d">Flip switch:</label>
104                                         <select name="slider" id="flip-d" data-role="slider" data-theme="e">
105                                                 <option value="no">No</option>
106                                                 <option value="yes">Yes</option>
107                                         </select> 
108                                 </div>
109                 
110                 <h2>Calling the switch plugin</h2>
111
112 <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>
113 <pre><code>
114 $('select').slider();                   
115 </code></pre>
116     
117                 </form>
118         </div><!--/content-primary -->          
119         
120         <div class="content-secondary">
121                 
122                 <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="d">
123                         
124                                 <h3>More in this section</h3>
125                                 
126                                 <ul data-role="listview" data-theme="c" data-dividertheme="d">
127                                 
128                                         <li data-role="list-divider">Form elements</li>
129                                         <li><a href="../docs-forms.html">Form basics</a></li>
130                                         <li><a href="../forms-all.html">Form element gallery</a></li>
131                                         <li><a href="../textinputs/index.html">Text inputs</a></li>
132                                         <li><a href="../search/">Search input</a></li>
133                                         <li><a href="../slider/">Slider</a></li>
134                                         <li data-theme="a"><a href="index.html">Flip toggle switch</a></li>
135                                         <li><a href="../radiobuttons/">Radio buttons</a></li>
136                                         <li><a href="../checkboxes/">Checkboxes</a></li>
137                                         <li><a href="../selects/">Select menus</a></li>
138                                         <li><a href="../forms-themes.html">Theming forms</a></li>
139                                         <li><a href="../forms-all-native.html">Native form elements</a></li>
140                                         <li><a href="../forms-sample.html">Submitting forms</a></li>
141                                         
142         
143                                 </ul>
144                 </div>
145         </div>          
146
147 </div><!-- /content -->
148
149 <div data-role="footer" class="footer-docs" data-theme="c">
150                 <p>&copy; 2011 The jQuery Project</p>
151 </div>
152         
153 </div><!-- /page -->
154
155 </body>
156 </html>
157