By some form generator a list of elements is rendered on a page and they all have validations on them. When I look in the HTML source, i see something like this:
<input type="text" id="email" name="email" data-val-required="No valid email address!" data-val="true">
I need to somehow have a dynamic way to enable/disable the validation for such an element. I tried to enable/disable the data-val
attribute, by setting it to false
and then back to true
. But it doesn't seem to be responding to that. The validation is always there!
Anyone has any idea how I can enable/disable validations on certain fields in a dynamic way?
I think this will help.
I actually found a solution that fits my needs better. I can do the following:
And with that i can 'toggle' any element that i want by adding or removing the classname
ignore
from an element.I think you need to write a custom validation attribute and then handle the data yourself in JQuery.
See this article: http://www.devtrends.co.uk/blog/the-complete-guide-to-validation-in-asp.net-mvc-3-part-2