客户端验证不适用于 dom 操作的元素?
我有一个带有选择元素和输入元素的简单表单。根据选择元素中的值,我可能需要也可能不需要验证输入元素。
我所做的是,根据选择元素中选择的内容,将输入元素上的“data-val”属性设置为“true”或“false”。这部分正在工作 - 我可以检查 firebug 中属性的值,它确实根据计划发生变化。
现在,为了让 jquery 不引人注目的验证注意到我调用的 dom 中的变化,
$.validator.unobtrusive.parse(document)
我尝试传递表单或元素,所以我想传递文档实际上只是我最近的尝试。我尝试传递表单的 jquery 对象以及 dom-form 元素。我还尝试仅验证输入元素调用
$.validator.unobtrusive.parseElement(myElement)
再次,我尝试使用 jquery 对象以及“nekid dom 元素”。
我在这里缺少什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,解析元素不能动态工作。试试这个 - 它对我和其他一些人有用......
http://xhalent.wordpress.com/2011/01/24/applying-unobtrusive-validation-to-dynamic-content/
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/
类似的问题(我之前没有使用搜索找到)
jquery.validate.unobtrusive 不适用于动态注入元素
有人建议从表单中删除验证器对象,因此调用解析将再次解析整个表单。
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.