Centralize some error messages from my form

a 夏天 提交于 2019-12-31 04:08:31

问题


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
    },
    ...

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
    },
    ...
});

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.


回答1:


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

One will always over ride the other.

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




回答2:


You can use text-align:center; property in css.



来源:https://stackoverflow.com/questions/42224986/centralize-some-error-messages-from-my-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!