jQuery 验证 ResetForm 不起作用添加到 Onclick 复选框

发布于 2025-01-03 22:04:56 字数 428 浏览 1 评论 0原文

我编写了一个小脚本,通过单击复选框将帐单地址复制到送货地址表单字段。

我已添加 validate.resetForm(); 作为此处建议:以确保当前表单错误已清除。

这似乎不起作用并且没有清除任何错误。

示例:http://jsfiddle.net/c5Qkt/

步骤:

  1. 点击“保存”按钮,显示错误消息。
  2. 在“帐单地址”中输入详细信息
  3. 检查“与预订信息相同”

如何清除所有错误,甚至在单击复选框后重新验证表格?

I wrote a small script which copies the billing address to the delivery address form fields onclick of a checkbox.

I have added validate.resetForm(); as suggested here: to ensure that the current form errors are cleared.

This doesn't seem to be working and clearing no errors.

Example: http://jsfiddle.net/c5Qkt/

Steps:

  1. Click the "Save" button, displays error messages.
  2. Enter details in "Billing Address"
  3. Check the "Same as Booking information"

How can I clear all errors and maybe even re-validate the form after click the checkbox?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

谎言 2025-01-10 22:04:56

您的问题是 resetFormvalidate.validate(...) 返回的验证器对象上的方法,而不是 jQuery 对象本身的方法。修复了小提琴 http://jsfiddle.net/pjucc/

var theForm = $(".validate");
var validate = null;
if (theForm.length) {
    validate = theForm.validate({ ... });
}
:
validate.form();

您想要触发验证的函数是 .form()

Your problem is that resetForm is a method on the validator object returned by validate.validate(...), and not on the jQuery object itself. Fixed fiddle http://jsfiddle.net/pjucc/

var theForm = $(".validate");
var validate = null;
if (theForm.length) {
    validate = theForm.validate({ ... });
}
:
validate.form();

The function you want to trigger validation instead is .form()

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