1

I'm using micrososofts unobtrusive jquery validation with MVC4 / razor and the default behavior appears to be to first validate on click of submit, and then after that validate onkeyup.

I'd like to change it so it starts validating onblur, and then after the first submit continues to validate on keyup as normal.

Is there a way I can change it to start validating on blur for all forms?

4

1 Answer 1

3

This is the default behaviour when using jquery validate directly or via Microsoft unobtrusive validation. If you enter a non valid entry into a field, that field will be validated on blur even before the field is submitted. If you focus and then blur a field without entering anything this field will only be validated on submitting the form.

From the documentation page section "A few things to look for when playing around with the demo"

Before a field is marked as invalid, the validation is lazy [but] if the user enters something in a non-marked field, and tabs/clicks away from it (blur the field), it is validated

I have forked the fiddle in the comment to demonstrate this using the unobtrusive plugin and some rendered html. http://jsfiddle.net/8wkS2/

"Links to jsfiddle.net must be accompanied by code." so here is the rendered markup produced by the server

<input type="text" name="field1" id="field1" 
data-val="true" 
data-val-required="This field is required"
data-val-length="The field LastName must be a string with a minimum length of 5." 
data-val-length-min="5" />
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.