Trigger jQuery Validation Manually?
I have i form i submit via jQuery's .submit(), unfortunately it does not trigger the validation plugin when i do it this way. If i place a submit button开发者_C百科 inside the form, it works perfectly.
Is there someway to trigger the plugin manually?
Thanks in advance.
$("#myButton").click(function(e) {
e.preventDefault();
if($("#myform").valid()){
// the form is valid, do something
} else{
// the form is invalid
}
});
You can use this
$(".selector").validate({
submitHandler: function(form){
form.submit();
}
});
which autosubmits the form it is valid, so you .validate() instead of submit()
You could try this:
$('#someForm').valid();
which could also be done in the submit handler:
$('#someForm').submit(function() {
if ($(this).valid()) {
} else {
}
});
精彩评论