如何在Sails.js中提供自定义模型验证消息? [英] How to provide custom model validation message in Sails.js?

查看:70
本文介绍了如何在Sails.js中提供自定义模型验证消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Sails.js中提供自定义模型验证消息?

How to provide custom model validation message in Sails.js?

Sails.js返回的验证消息不是用户友好的,所以我想提供自定义验证如需要的规则,minLength等的消息...但不知道如何。它不在文档中,我也检查了Anchor.js的文档w / c是Sails使用的验证器,但它也不存在。

The validation messages returned by Sails.js is not user friendly so I wanted to provide a custom validation message for rules like required, minLength etc... but don't really know how. It's not in the docs and I also checked the docs of Anchor.js w/c is the validator used by Sails but its also not there.

更新:

上周没有回复,所以我实施了自己的解决方案,希望分享因为它可能对其他人有用 - 我如何使用自定义Sails.js中的验证消息

Haven't got a response last week so I implemented my own solution, wanted to share it since it might be useful for others - How I use custom validation messages in Sails.js

另一种替代方法是使用以下评论中的@Rifat解决方案:)

Another alternative and better way is to use the solution of @Rifat found in the comments below :)

另一个非常好的选择(信用:sfb_) - https:/ /gist.github.com/basco-johnkevin/8436644

Another very good alternative (credits to: sfb_ ) - https://gist.github.com/basco-johnkevin/8436644

推荐答案

由于Sails.js尚不支持使用自定义模型验证消息,我们可以使用以下解决方案:

Since Sails.js doesn't yet support using custom model validation messages, we can use these solutions:

1) @ johnkevinmbasco的解决方案

2) @ sfb_的解决方案

3) @ rifats解决方案

这篇关于如何在Sails.js中提供自定义模型验证消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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