开发者

jQuery validation: Checking if form is validated?

I would like to run a function if my form has completely validated according to my defined rules (Not shown below).

The below code doesn't work as I would like it to开发者_如何学JAVA, most certainly depending on the fact that the success function is called on a per-input basis and not globally for the complete form .

Are there any workarounds to get a global success callback that runs when the complete form validates properly?

$("#myForm").validate({

    success: function(label) {

        if ($("#myForm").valid()) {
            runMyFunction();
        }

    },

    rules: {
        //...
    }

});


$("#myForm").validate({

    rules: {
        //...
    },
    success: function(label) {           

    },
   submitHandler: function(e) {
          e.preventDefault();
          runMyFunction();           
    }    
 });

REF: http://docs.jquery.com/Plugins/Validation/validate#toptions

you dont have to do

if ($("#myForm").valid()) {
            runMyFunction();
        }

the success callback is called only when the from is validated just runMyFunction()


you can you use mass validate of livevalidation

please checkout their api , it has mass validator that does what you exactly want.

http://livevalidation.com/

http://livevalidation.com/documentation#LiveValidationMassValidate

you can also use jquery bassistance validation http://docs.jquery.com/Plugins/Validation/valid


I ended up using this modification to the validation plugin:

http://forum.jquery.com/topic/suggestion-for-validate-plugin

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜