jQuery 验证 - resetForm() 的行为不符合预期
有问题的网站是 http://epraxadev.com/kw/palisade-palms/
"单击此处获取宣传册”和“了解有关 Palisade Palms 的更多信息”都会弹出一个灯箱,其中包含要填写的相同 HTML 表单...“了解更多...”链接还更改了表单中的一些 HTML(隐藏表单字段的值以及所需的字段)。
我使用 Colorbox 作为灯箱,对于它的 onClosed 事件,我用它来重置表单:
onClosed: function() {
$('#brochure-form label em').remove();
$('#brochure-form').data('validator').resetForm();
}
现在问题是:
- 用户尝试提交“小册子”表单,但验证失败。用户关闭灯箱。
- 用户打开“了解更多”灯箱,并尝试提交表单...现在,它不再使用正确的验证规则(仅需要电子邮件和引荐来源网址),而是要求填写所有字段(就像案例与“宣传册表格”)
是否可以添加一些东西到 onClosed 函数中,以清理所有验证规则?
谢谢你们!
Site in question is http://epraxadev.com/kw/palisade-palms/
"Click here for brochure" and "Learn More about Palisade Palms" both bring up a lightbox with the same HTML form to be filled out...the "learn more..." link also changes some of the HTML in the form (the value for a hidden form field, and the fields required).
I'm using Colorbox for the lightbox, and for its onClosed event, I have this to reset the form:
onClosed: function() {
$('#brochure-form label em').remove();
$('#brochure-form').data('validator').resetForm();
}
Now here's the problem:
- User tries to submit the "brochure" form, but it fails validation. User closes the lightbox.
- User opens up the "Learn more" lightbox, and tries to submit the form...now, instead of using the correct validation rules (only requiring e-mail and referrer), it requires all fields to be filled out (as is the case with the "Brochure Form")
Is there something that I can add to the onClosed function, to clean up all the validation rules?
Thanks guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过手动添加 & 修复了它分别在 onComplete 和 onClosed colorbox 事件期间删除所需输入的“必需”类。
之前,我使用 添加了所需的输入规则,
并且这些规则没有使用 resetForm() 函数正确清除。
您可以在http://epraxadev.com/kw/palisade-palms/
您可以在 http://epraxadev.com 查看旧的、无法工作的版本/kw/palisade-palms/test.html
I fixed it by manually adding & removing the "required" class to desired inputs during the onComplete and onClosed colorbox events, respectively.
Before, I was adding the required input rules with
And those rules weren't properly cleaned out with the resetForm() function.
You can see the working code at http://epraxadev.com/kw/palisade-palms/
You can see the old, non-working version at http://epraxadev.com/kw/palisade-palms/test.html