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
2 Answers
Reset to default 5You 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