If you try to parse a form that is already parsed it won’t update
What you could do when you add dynamic element to the form is either
-
You could remove the form’s validation and re validate it like this:
var form = $(formSelector) .removeData("validator") /* added by the raw jquery.validate plugin */ .removeData("unobtrusiveValidation"); /* added by the jquery unobtrusive plugin*/ $.validator.unobtrusive.parse(form);
-
Access the form’s
unobtrusiveValidation
data using the jquerydata
method:$(form).data('unobtrusiveValidation')
then access the rules collection and add the new elements attributes (which is somewhat complicated).
You can also check out this article on Applying unobtrusive jquery validation to dynamic content in ASP.Net MVC for a plugin used for adding dynamic elements to a form. This plugin uses the 2nd solution.