diff --git a/docs/forms/switch/events.html b/docs/forms/switch/events.html new file mode 100644 index 00000000000..cbc65e5661b --- /dev/null +++ b/docs/forms/switch/events.html @@ -0,0 +1,100 @@ + + +
Since the native select field is changed by flip switch, you can watch for events on the native select field instead of needing to go through the slider plugin. Bind to the change event.
+$( ".selector" ).bind( "change", function(event, ui) { + ... +}); +
The Flip switch plugin has the following custom event:
create
This event is used to find out when a flip switch was created. It is not used to create a custom flip switch. The flip switch create event can be used like this:
+$( ".selector" ).slider({ + create: function(event, ui) { ... } +}); +
A binary "flip" switch is a common UI element on mobile devices that is used for any binary on/off or true/false type of data input. You can either drag the flip handle like a slider or tap on each half of the switch.
To create a flip toggle start with a select 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 in the correct order. Set the for attribute of the label to match the ID of the input so they are semantically associated and wrap them in a div with the data-role="fieldcontain" attribute to group them.
select
for
label
input
div
data-role="fieldcontain"
+<div data-role="fieldcontain"> + <label for="slider">Flip Switch:</label> + <select name="slider" id="slider" data-role="slider"> + <option value="on">On</option> + <option value="off">Off</option> + </select> +</div> +
The flip toggle switch is displayed like this:
If you manipulate a flip switch via JavaScript, you must call the refresh method on it to update the visual styling. Here is an example:
+var myswitch = $("select#bar"); +myswitch[0].selectedIndex = 1; +myswitch .slider("refresh"); +
The flip switch plugin has the following methods:
enable
+$('select').slider('enable'); +
disable
+$('select').slider('disable'); +
refresh
+//refresh value +$('select').slider('refresh'); + +//refresh and force rebuild +$('select').slider('refresh', true); +
The flip switch plugin has the following options:
initSelector
default:jqmData(role='slider')"
This is used to define the selectors (element types, data roles, etc.) that should be used as the trigger to automatic initialization of the widget plugin. To affect all flip switches, this option can be set by binding to the mobileinit event:
$( document ).bind( "mobileinit", function(){ + $.mobile.slider.prototype.options.initSelector = ".mySwitch"; +}); +
theme
default: null, inherited from parent
Sets the theme swatch color scheme for the select element. This is a single letter from a-z that maps to the swatches included in your theme. By default, a flip switch will inherit the same swatch color as it's parent container if not explicitly set. This option is also exposed as a data attribute: data-theme="a"
data-theme="a"
$('select').slider({ theme: "a" });