facebook

[SOLVED] fire custom action when toggle status changes?

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #319302 Reply

    WiZaxx
    Participant

    Is 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

    #319336 Reply

    support-michael
    Keymaster

    @WiZaxx

    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');
            }
          });
    }
    #335512 Reply

    lemorlenny
    Member

    @support-wayne wrote:

    @WiZaxx

    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?.

    #335516 Reply

    paulD
    Member

    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.

    #335517 Reply

    lemorlenny
    Member

    @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.

    #335518 Reply

    paulD
    Member

    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.

    #335525 Reply

    lemorlenny
    Member

    @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'));
    
    
    #335537 Reply

    paulD
    Member

    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

    #335538 Reply

    lemorlenny
    Member

    @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.

Viewing 9 posts - 1 through 9 (of 9 total)
Reply To: [SOLVED] fire custom action when toggle status changes?

You must be logged in to post in the forum log in