JQM 1.4.3 everything about flip switches does not work for me
To whom it may concern,
I'm testing out the flip switch feature of JQM 1.4.3 but for some reason everything I know about them data-wise is not working for me.
What I'm testing is on flip switch change, I want to get the current value, but no matter how many times I change the flip switch, the value does not match the state displayed.
I'm also trying to toggle the flip switch on a button press. Value wise, it is toggling between on and off but the flip switch does not show the correct state even after calling the refresh method recommended from the JQM 1.4.3 API documentations.
The documentations for refreshing a flip switch that I'm looking at is:
link
My HTML code:
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Flip switch test</title>
-
- <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.css" />
- <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
- <script src="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.js"></script>
-
- </head>
- <body>
- <div data-role="page" class="myPage">
- <a data-role="button" class="toggleFlipswitchBTN" data-inline="true">TOGGLE FLIP</a>
- <input type="checkbox" data-role="flipswitch" class="flipswitchTest" data-on-text="Online" data-off-text="Offline" data-wrapper-class="flipswitchTestWrapper" />
- </div>
- </body>
- </html>
My JavaScript code:
- $(document).on("pagebeforecreate", ".myPage", function(){
- $(".toggleFlipswitchBTN").on("click", toggleFlipSwitch);
- $(".flipswitchTest").on("change",flipswitchChange);
- });
- function toggleFlipSwitch(){
- var currentStatus = $(".flipswitchTest").val();
- var toggleTo = {
- "on" : "off",
- "off": "on"
- };
- var toggleToStatus = toggleTo[currentStatus];
- alert("CURRENTLY: " + currentStatus + " CHANGING TO " + toggleToStatus);
- $(".flipswitchTest").val(toggleToStatus).flipswitch("refresh");
- }//toggleFlipSwitch
-
- function flipswitchChange(e){
- var currentStatus = $(".flipswitchTest").val();
- alert("FLIPSWITCH CHANGED TO: " + currentStatus);
- }
My CSS code:
- .flipswitchTestWrapper.ui-flipswitch .ui-btn.ui-flipswitch-on {
- text-indent: -3.6em;
- }
- .flipswitchTestWrapper.ui-flipswitch .ui-flipswitch-off {
- text-indent: 0.3em;
- }
I've made a JS Bin example which can be found at:
link
The HTML and CSS coding is basically a copy and paste from the demo source for flipswitch found at:
link
Can someone please help explain to me what I'm doing wrong and if possible, the correct methods.
Thank you.