This topic contains 6 replies, has 5 voices, and was last updated by ap ap 6 months, 2 weeks ago.

Submitting Forms with the Switch Component


  • rubyhaus
    Participant

    Posts: 1
    Member Reply #12475

    I have been playing with the new v5 demo and the one thing I can’t figure out (which was the same with v4 and the Material controls) is how you get the switch/checkbox state. When I implement these controls on a page, jQuery always says they aren’t checked and they don’t submit to the server (ASP.NET), even though they are toggled. I’m obviously missing something simple here, but I can’t figure it out.

    Here is the demo: http://keenthemes.com/metronic/preview/index.php?page=components/forms/controls/switch&demo=default. How do I get the current state of the “With Icon” demo in the second column of the first portlet? I tried adding an ID to it via Chrome’s inspection tools and using jQuery, but it always tells me it’s unchecked.

    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #12600

    Hi,

    You can change the checkbox state using jQuery’s prop method using it with the checkbox ID:

    $(‘#my-check’).prop(“checked”, true);

    The above code will change the actual checkbox’s state and you will be able to submit it.

    If you need any further help please let us know.

    Thanks.


    rubyhaus
    Participant

    Posts: 1
    Member Reply #12605

    But how do we go about using this checkbox without that? If I flip it and it doesn’t check the underlying checkbox, then it’s a fancy UI that doesn’t really do anything. Or, is there some kind of event when that is flipped that fires so jQuery can be used to check the actual checkbox?

    Sean
    Sean
    Keymaster

    Posts: 4527
    Support Staff Reply #12678

    Hi,

    We have just double checked it and the manually checked checkbox/radios are submittable with normal form submit.
    Can you try to debug your form submit by dumping the entire POST variable ? Or you are able to submit standard checkbox/radio but the Metronic ones ? But according to our testing the checkboxes/radios are working as expected.

    Thanks.


    jonasgraterol
    Participant

    Posts: 1
    Member Reply #19653

    I have the same problem, if there is no event attached to event change in m-switch component, this is a beautiful but useless component.

    Should be a event attached to the changes in the switch to update the value of the checkbox previous to be submited. This component is pure css? no JS/jquery ?


    CondonesMix
    Participant

    Posts: 3
    Member Reply #19882

    I don’t think it useless.

    I use capturing event by Jquery by css class and now this switch disapeared in metronic, and the new one it’s worst in my opinion.

     

     

     

     

    ap
    ap
    Participant

    Posts: 4
    Member Reply #19894

    I use the following to check the status of the checkbox to capture with jquery and post with ajax.


    $(document).on('click','#switch',function() {
    var switchState = $('#switch').is(':checked');
    console.log(switchState);
    });

You must be logged in to reply to this topic.