views:

83

answers:

2
+1  Q: 

JQuery Validation

var formValidationRules = {
 rules: {
  password: {
   required: true,
   remote: '/account/delete'
  }
 },
 messages: {
  "password": { required: "Please enter your password", remote: "Invalid password, try again." }
 }
};

I wrote such validation, but I found out the the Validation will check for each event for the remote and the required.

I would like to perform such task only when submitting, (no blur, no keyup) - what is the best way to do this?

Thanks.

+1  A: 

See the onfocusout and onkeyup options:

var formValidationRules = {
        rules: {
                password: {
                        required: true,
                        remote: sitemap.accountSettings.validatePassword
                }
        },
        //wording
        messages: {
                "password": { required: "Please enter your password", remote: "Invalid password, try again." }
        }
        onfocusout: false,
        onkeyup: false
};
karim79
sounds good but such code won't cause submit at all....so even pressing the submit won't cause the validation...
rabashani
+1  A: 

Not sure which validation plugin you are using but if you use the basic validation plugin from jquery you just add the following code.

My form only validates on form submit and this seems like what you are wanting.

$.validator.setDefaults({
 submitHandler: function() { form.submit(); }
});
Scott Gottreu