Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event hooks for MVC unobtrusive remote validation

Is there a way to hook into MVC3 unobtrusive remote validation on the client, before data is submitted to the remote method, and after a result is returned from the remote method?

I am trying to tell a remote validator to only perform validation if the submit button is clicked. The normal behavior is to validate several times, such as during keypress, blur etc. This is no good, as the validation method in question needs to call a non-idempotent operation. I need to make sure that method is only invoked if the user has clicked the submit button.

If I could hook into a before event, I could set a field in the form that flags the submit button as being clicked or not. However I would need to reset this flag after the remote method returns a validation result.

Any other suggestions? This is for validating a password using the ASP.NET Membership Provider's Membership.ValidateUser(string username, string password) method. This method will increment the FailedPasswordAttemtCount each time an invalid password is sent, so I don't want it to execute during blur, keypress, etc.

like image 290
danludwig Avatar asked May 02 '12 12:05

danludwig


1 Answers

You could override the default validation options for the current page:

$.validator.setDefaults({
    onkeyup: false,
    onfocusout: false,
    onsubmit: true
});
like image 198
Darin Dimitrov Avatar answered Nov 18 '22 07:11

Darin Dimitrov