Blog from Saravanan Arumugam

Let us talk about Technologies

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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: