Adding dynamic elements with unobtrusive jQuery validate in Asp.net-Mvc

August 05, 2013

If you are trying to parse a form that is already parsed it won’t update

What you could do if you are adding dynamic elements to the form is by either

1- Remove the form’s validation and re validate it it would be 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)

2- Access the form’s unobtrusiveValidation data using the jquery data method

we can use $(form).data(‘unobtrusiveValidation’) and access the rules collection and add the new elements attributes (which is somewhat complicated)


for an example on how that is done check this article, this is a plugin used for adding dynamic elements to a form, its source code is easy to read link here


Nadeem Khedr

Written by Nadeem Khedr citizen of the world, you can find me on Twitter & Github