Pat Long - Munkii Yebee
Pat Long - Munkii Yebee

Reputation: 3629

Not firing validation for Cancel link with jQuery validate

We are using jQuery Unobtrusive validate and MVC4. Our forms have a cancel anchor that we wanted to use to client-side reset the form.

We are using onFocusOut validation.

If we are focussed on a field that is invalid and press the cancel link the action of losing focus on the input field fires validation.

I know that if it was a submit button we could use a cancel class but that would only cause the submit time validation to not fire. The onFocusOut validation still fires.

We have a solution which involves us trapping onMouseDown on the cancel link, setting a DoNotValidate flag and then turning that flag off after. It works but does seem like a Kludge.

Is it because we are using onFocusOut? How do other people handle cancel when using OnFocusOut?

Upvotes: 1

Views: 188

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038820

I am afraid that there is no clean solution to this other than disabling validation to be performed in the onblur event. You could disable it and perform client side validation only for the onsubmit event. Otherwise the workaround you've discovered seems viable.

Upvotes: 1

Related Questions