jQuery 验证 - resetForm() 的行为不符合预期

发布于 2024-08-31 08:39:47 字数 682 浏览 1 评论 0原文

有问题的网站是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪都笑了 2024-09-07 08:39:47

我通过手动添加 & 修复了它分别在 onComplete 和 onClosed colorbox 事件期间删​​除所需输入的“必需”类。

之前,我使用 添加了所需的输入规则,

$('#brochure-form').validate({
            rules: {
                first_name: "required",
                last_name:  "required",
                email: "required",
                phone: "required",
                address: "required",
                city: "required",
                state: "required",
                zip: "required",
                referrer: "required"
            }
        }); 

并且这些规则没有使用 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

$('#brochure-form').validate({
            rules: {
                first_name: "required",
                last_name:  "required",
                email: "required",
                phone: "required",
                address: "required",
                city: "required",
                state: "required",
                zip: "required",
                referrer: "required"
            }
        }); 

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文