- This topic has 8 replies, 4 voices, and was last updated 12 years, 4 months ago by
lemorlenny.
-
AuthorPosts
-
WiZaxxParticipantIs it possible to attach a function to the toggle component so when it changes status it can actually do something rather behaving dumb???
Thank you
August 29, 2011 at 10:16 am #319336
support-michaelKeymasterThe toggle widget is implemented in HTML using an styled checkbox, example:
<div id="m1-Untitled1-toggle1" class="m1-toggle m1-iscroll-no-prevent-default"> <input type="checkbox" checked="true"/> </div>
In the following snippet of JQuery I added to the phoneui.documentReadyHandler function a call to my handler function when the toggle widget changes value:
/** * Called when document is loaded. */ phoneui.documentReadyHandler = function() { $('#m1-Untitled1-toggle1 input').change( function() { if ($(this).val()) { alert('toggle value: ON'); } else { alert('toggle value: OFF'); } }); }
February 17, 2013 at 9:38 am #335512
lemorlennyMember@support-wayne wrote:
The toggle widget is implemented in HTML using an styled checkbox, example:
<div id="m1-Untitled1-toggle1" class="m1-toggle m1-iscroll-no-prevent-default"> <input type="checkbox" checked="true"/> </div>
In the following snippet of JQuery I added to the phoneui.documentReadyHandler function a call to my handler function when the toggle widget changes value:
/** * Called when document is loaded. */ phoneui.documentReadyHandler = function() { $('#m1-Untitled1-toggle1 input').change( function() { if ($(this).val()) { alert('toggle value: ON'); } else { alert('toggle value: OFF'); } }); }
Why when I try this example I receive always ON alert?.
February 17, 2013 at 1:42 pm #335516
paulDMemberThats because you have to give the toggle 1 a value for the if statement to work. At the moment because there is no value set at the .val() The if statement fires ON every time.
February 17, 2013 at 1:58 pm #335517
lemorlennyMember@paulD wrote:
Thats because you have to give the toggle 1 a value for the if statement to work. At the moment because there is no value set at the .val() The if statement fires ON every time.
you means in the value property?, I tried to insert a value (literal,boolean or numeric) but $(this).val() return only this, can you clarify pls.
Thanks.
February 17, 2013 at 4:02 pm #335518
paulDMemberIn the widget properties panel for the toggle widget you can assign values for the two states of the toggle.
thats the value you need to use in the if statement.
February 18, 2013 at 1:32 am #335525
lemorlennyMember@paulD wrote:
In the widget properties panel for the toggle widget you can assign values for the two states of the toggle.
thats the value you need to use in the if statement.
Ok, I used this:
alert( $('input[name="toggle1"]').is(':checked'));
February 18, 2013 at 5:53 am #335537
paulDMemberSo sorry Lenny i was wrong in what I was saying. I am also learning!
I had a play this morning and got it to work using
/** * Called when document is loaded. */ phoneui.documentReadyHandler = function() { $('#m1-toggle-toggle1 input').change( function() { if ($('input[name="toggle1"]').is(':checked')) { alert('toggle value: ON'); } else { alert('toggle value: OFF'); } }); }
It now fires on and off depending on the state. Hope this helps
Paul
February 18, 2013 at 6:07 am #335538
lemorlennyMember@paulD wrote:
So sorry Lenny i was wrong in what I was saying. I am also learning!
I had a play this morning and got it to work using
/** * Called when document is loaded. */ phoneui.documentReadyHandler = function() { $('#m1-toggle-toggle1 input').change( function() { if ($('input[name="toggle1"]').is(':checked')) { alert('toggle value: ON'); } else { alert('toggle value: OFF'); } }); }
It now fires on and off depending on the state. Hope this helps
Paul
Many thanks for your reply Paul.
-
AuthorPosts