views:

102

answers:

1

By default, if a user enters a value in a field, the 'eager' validation kicks in. Is there any way to disable 'eager' validation before submit and then enable it after an invalid submit has happened?

I've used $.validator.setDefaults() to initially set the onkeyup and onfocusout properties to false.

In the invalidHandler method I rerun the $.validator.setDefaults(), setting onkeyup and onfocusout properties to true.

No luck with this approach.

Basically, I only want the 'eager' validation to take place after the user tries to submit an invalid form.

Thanks for any help.

A: 

I figured out a simple solution. I just set a custom flag in the invalidHandler method and then check it in the other methods to determine what functionality to support.

$.validator.setDefaults({
    invalidHandler: function(form, validator) {     
        // Set a custom flag to activate certain functionality
        // after the user has clicked the form submit.
        validator.settings.invalidSubmit = true;
    },
    showErrors: function(errorMap, errorList) {
        // Check our custom flag
        if(this.settings.invalidSubmit) {
            // Do something...
        }
    }
});
Ryan Fitzer