Disable client side validation for hidden fields in MVC

This is something that bugged me for a while, there is also quite a bit of confusion online about how to do it.

If you need to enable and disable client side validation for fields that become visible/hidden on a form as user fills out the form it is actually quite easy to do.

Just go about hiding and showing the controls you need to but add this line of javascript after your jqueryval script bundle:

jQuery.validator.defaults.ignore = ":hidden";

Basically this will cause jquery validation to ignore hidden fields in your form, which is what you want if they are hidden.

Source: MVC unobtrusive validation – conditionally disable/enable validation


Published by

Alan Feekery

Developer, Gamer, Musician, Cyclist and big Motorsport fan... enjoys the odd cup of coffee :)

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s