Question

I have a simple form with a select element and an input element. Depending on the value in the select element i might or might not need the input element validated.

What i did is, i set the 'data-val' attribute on the input element to either 'true' or 'false' depending on what is selected in the select element. This part is working - i can inspect the value of the attribute in firebug and it does change according to the plan.

Now, in order to have the jquery unobtrusive validation to notice the change in the dom i call

$.validator.unobtrusive.parse(document)

I tried passing the form or the element, so i guess passing the document is actually just my latest attempt. I tried passing the jquery object of the form, as well as the dom-form element. I also tried validating only the input element calling

$.validator.unobtrusive.parseElement(myElement)

Again, i tried with the jquery object as well as the 'nekid dom element'.

What am i missing here?

Was it helpful?

Solution

yeah, parse element does not work dynamically. Try this -it worked for me and a fair few others....

http://xhalent.wordpress.com/2011/01/24/applying-unobtrusive-validation-to-dynamic-content/

OTHER TIPS

Similar question (that i didn't find using search earlier) jquery.validate.unobtrusive not working with dynamic injected elements

There is a guy suggesting removing the validator object from the form, so calling parse will parse the whole form again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top