Client validation does not work on dom manipulated elements?

醉酒当歌 提交于 2019-12-12 10:19:09

问题


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?


回答1:


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/




回答2:


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.



来源:https://stackoverflow.com/questions/4872552/client-validation-does-not-work-on-dom-manipulated-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!