I have jQuery validation on my form. When I click submit button, ‘save’ function is called:
function save(){
var form = document.getElementById('myForm');
form.submit(); // <- jquery validation is not called
$(form).submit() // <- jquery validation works
}
Why form.submit() is not validating my form?
The native
submitmethod (W3 spec) will submit the form, and nothing else. It does not fire a cancelablesubmitevent (see concept of form submit).jQuery’s
submitmethod is an alias for.trigger("submit"), but “in addition, the default submit action on the form will be fired [invoked], so the form will be submitted.“Your validation will listen for those submit events, which don’t happen when using the native submit method.