开发者

Trigger jQuery Validation Manually?

开发者 https://www.devze.com 2023-03-13 20:25 出处:网络
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 perfectl

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 {

    }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消