xVal 验证失败时的事件?

发布于 2024-08-26 22:24:53 字数 251 浏览 4 评论 0原文

我有一个注册表单,利用 xVal 来处理表单上的所有验证。它工作得很好,但有一个例外:用户没有得到反馈,因为页面上的另一个元素(告诉用户他们的用户名将是他们的电子邮件地址的提示)绘制在 span 元素的顶部,xVal 在注意到时会吐出一个问题。

如果我有办法检测 xVal 的电子邮件字段何时出现问题,我可以切换该工具提示的可见性并继续前进,但我不知道该怎么做。我知道 xVal 在底层使用了 jquery.validate.js;有什么活动或事情我可以参与来做这件事吗?

I have a registration form leveraging xVal to handle all validation on the form. It works really well, with one exception: the user doesn't get feedback because another element on the page (a tip telling the user that their username will be their email address) draws on top of the span element xVal spits out when it notices a problem.

If I had a way to detect when xVal has a problem with the email field, I could just toggle the visibility of that tooltip and be on my way, but I'm not sure how to do so. I know that xVal uses jquery.validate.js under the hood; is there an event or something I could tie into to do this?

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

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

发布评论

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

评论(1

一场信仰旅途 2024-09-02 22:24:53

在不真正了解 xVal 以及如何/是否可以轻松设置 jQuery 验证的自定义选项的情况下,如果仅使用 jQuery 验证插件,您将执行以下操作。

您可以连接 showErrors 回调和/或 invalidHandler 回调

检查 jQuery 验证插件选项文档 了解更多信息

,例如像这样的东西应该可以工作(但要知道错误不再存在是比较棘手的)

$(".yourformselector").validate({
    showErrors: function(errorMap, errorList) {
        var check = jQuery.inArray($("#idofemailfield").get(0), errorList);
        if(check === undefined |< check === -1) {
            //hide the tooltip
        }
        this.defaultShowErrors();
    }
});

Without really knowing xVal and how/if you can easily set custom options for the jQuery validation you would do the following if just using the jQuery Validation plugin.

You would hook up the showErrors callback and/or the invalidHandler callback

Check the jQuery Validation Plugin options documentation for more info

e.g. something like this should work (but it's trickier to know the error is no longer there)

$(".yourformselector").validate({
    showErrors: function(errorMap, errorList) {
        var check = jQuery.inArray($("#idofemailfield").get(0), errorList);
        if(check === undefined |< check === -1) {
            //hide the tooltip
        }
        this.defaultShowErrors();
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文