集中一些来自我表单的错误消息 [英] Centralize some error messages from my form

查看:75
本文介绍了集中一些来自我表单的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在使用errorPlacement为每个输入打印错误消息:

Currently, I'm using errorPlacement to print error message for each input :

$('#my_form').validate({
    errorPlacement: function(error, element) {
         // Some code that print error below each inputs
    },
    ...

然后,我尝试使用showErrors集中错误消息,如下所示:

Then, I tried to centralize errors messages with showErrors, like this :

    showErrors: function(errorMap, errorList) {
         // Some code that centralize each error for each input in one place
    },
    ...
});

工作正常,除了现在我只想集中我的表单中的一些错误消息,而不是全部集中.像只将showErrors用于我要集中的输入,然后将errorPlacement用于其他输入.

It works fine, except that now I would like to centralize only some errors messages of my form, not all of them. Something like using showErrors only for inputs that I want to centralize, then errorPlacement for the others.

推荐答案

类似于仅将showErrors用于我要集中的输入,然后将errorPlacement用于其他输入的情况.

Something like using showErrors only for inputs that I want to centralize, then errorPlacement for the others.

一个将永远超过另一个.

One will always over ride the other.

您必须对所有内容都使用showErrors,在其中检查errorMaperrorList,并有条件地将每条消息放在需要的地方.

You'll have to use showErrors for everything, where you inspect the errorMap and errorList and conditionally place each message where you need it.

这篇关于集中一些来自我表单的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆