5

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, 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: {
        //...
    }

});

3 Answers 3

1
$("#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()

Sign up to request clarification or add additional context in comments.

1 Comment

success callback doesn't work on a global basis and is called for every passed validation, ie. for every properly inputted form by the user.
0

I ended up using this modification to the validation plugin:

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

1 Comment

Please include the relevant code within your answer to make it fully self-contained.
-1

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

6 Comments

Hi! As you can see in my example, I already call the valid function in the success callback. Unfortunately it doesn't work. Any suggestions?
you can see @3nigma's answer.. It seems valid.. :)
Answer makes no sense... OP is asking about jQuery Validate plugin by Bassistance.
doesn't seem so from the question
Title says "jQuery validation:", question is tagged [jquery-validate], and code contains .validate(). All three things ==> Bassistance Validation plugin.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.