最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQuery Validation Plugin submitHandler doesnt work for me - Stack Overflow

programmeradmin9浏览0评论

Hello i got the following issue my following code doesn't work for me and i cant figure out why. I hope you guys can help me.

Edit: The submit handler simply doesn't get called. I don't even get the alert message. I wanted to disable the submit button till the form is validated.

    $('form').validate({

        onsubmit: true,
        debug: true,
        errorLabelContainer: "#errorBox",
        rules: {
            user_email: {
                minlength: 4,
                email: true,
                required: true
            },
            user_textField: {
                minlength: 3,
                required: true
            },
            user_phone: {
                required: true,
                number: true,
                minlength: 4
            },
            user_fax: {
                number: true,
                minlength: 4
            },

            user_plz: {
                required: true,
                number: true,
                minlength: 5
            }
        },
        submitHandler: function (form) {
            $('form').find(":submit").attr("disabled", true).attr("value","Submitting...");
            alert("hie");
            form.submit();
        }
    }); 

I also got a submit button:

<button class="btn btn-primary pull-right continuePaymentProcess" type="submit">Weiter</button>

Best Regards Grandy

Hello i got the following issue my following code doesn't work for me and i cant figure out why. I hope you guys can help me.

Edit: The submit handler simply doesn't get called. I don't even get the alert message. I wanted to disable the submit button till the form is validated.

    $('form').validate({

        onsubmit: true,
        debug: true,
        errorLabelContainer: "#errorBox",
        rules: {
            user_email: {
                minlength: 4,
                email: true,
                required: true
            },
            user_textField: {
                minlength: 3,
                required: true
            },
            user_phone: {
                required: true,
                number: true,
                minlength: 4
            },
            user_fax: {
                number: true,
                minlength: 4
            },

            user_plz: {
                required: true,
                number: true,
                minlength: 5
            }
        },
        submitHandler: function (form) {
            $('form').find(":submit").attr("disabled", true).attr("value","Submitting...");
            alert("hie");
            form.submit();
        }
    }); 

I also got a submit button:

<button class="btn btn-primary pull-right continuePaymentProcess" type="submit">Weiter</button>

Best Regards Grandy

Share Improve this question edited Aug 21, 2013 at 9:59 Grandy asked Aug 21, 2013 at 9:52 GrandyGrandy 451 gold badge1 silver badge4 bronze badges 2
  • Saying 'it doesn't work' is not enough information. Please include details of expected behaviour, and what happens, and why it does not meet what you need. – Rory McCrossan Commented Aug 21, 2013 at 9:55
  • The submit handler simply doesn't get called. I don't even get the alert message. I wanted to disable the submit button till the form is validated. – Grandy Commented Aug 21, 2013 at 9:59
Add a ment  | 

2 Answers 2

Reset to default 5

You don't need the onsubmit: true line because that's the default behavior. Important: as per docs,

Validate the form on submit. Set to false to use only other events for validation. Set to a Function to decide for yourself when to run validation. A boolean true is not a valid value.

In other words, you must remove that line because true will break the plugin.

As far as the submitHandler "not working", it works as per the documentation. The submitHandler callback function fires when the form is valid.

You say, "I wanted to disable the submit button till the form is validated."

Since the submitHandler doesn't get fired until the the form is valid, your code to disable the button doesn't fire until after the form is validated.

See your code: http://jsfiddle/aDAGL/

I too faced the same issue. Please check all the input elements in the form and provide "name" attribute to all the elements . This helped in my case.

Thank you

发布评论

评论列表(0)

  1. 暂无评论