Blog from Saravanan Arumugam

Let us talk about Technologies

Monthly Archives: December 2012

Cancel Validation for a Submit button when jQuery validation is enabled in the page


I have a MVC 3 page where I wanted the unobtrusive validation to happen for my input fields. But on click of one of the buttons I don’t want to trigger the javascript validation.

While going through “jquery.validate.js” for a solution, the solution I found was an easy one.

Here’s the code from jquery.validation.js that gave me the clue.

// allow suppresing validation by adding a cancel class to the submit button
inputsAndButtons.filter(".cancel").click(function () {
	validator.cancelSubmit = true;
});

So if I simply add the class=“cancel” to a submit button, the validation is ignored for that click.

Advertisements