node.js - meteor 自动形成简单模式 : how to customize validation message?

标签 node.js validation meteor meteor-autoform

我有这个架构:

Users = new Meteor.Collection('users', {
    schema: {
        firstname: {
            type: String,
            label: "First name",
            max:50
        },
        lastname: {
            type: String,
            label: "Last name",
            max:50
        },
        email: {
            type: String,
            label: "E-mail",
            regEx: SimpleSchema.RegEx.Email,
            optional: false,
            max:50
        },
        tel: {
            type: String,
            label: "Phone",
            optional: false,
            max:50
        },
        zip: {
            type: String,
            label: "Zip code",
            optional: false,
            regEx: /^[0-9]{5}$/,
            max:50
        },
        city: {
            type: String,
            label: "City",
            optional: false,
            max:50
        },
    }
});

在我的模板中,我像这样使用 Autoform:

<template name="userSubmit">
    {{> quickForm collection="Users" id="insertUserForm" type="insert" validation="blur"}}
</template>

我想自定义邮政编码的错误消息。而不是“不符合正则表达式”,我想有:“你的邮政编码只能是数字,应该有 5 个字符”

我该怎么做?

最佳答案

您可以像这样覆盖模式的消息对象:

mySimpleSchemaInstance.messages({
  "regex": "Your Zip Code can only be numeric and should have 5 characters"
})

查看更多: https://github.com/aldeed/meteor-simple-schema#customizing-validation-messages

关于node.js - meteor 自动形成简单模式 : how to customize validation message?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23971032/

相关文章:

node.js - compoundjs 中的问题 "Adapter is not define'

node.js - 如何在socket.io中重用redis连接?

提交时 JavaScript 表单验证。

javascript - 动态生成数据目标

javascript - 在对象数组中搜索特定项目并查询属性是否存在

javascript - 在 Node.js 中使用 "global"

javascript - 更改 MongoDB 文档/对象中的所有 MongoDB 对象 ID

javascript - 如何根据电子邮件地址域/TLD 验证 jQuery 中的表单字段? (.com、.net、.edu?)

Xcode - 由于解决 info.plist 和权利中的变量/占位符的奇怪问题而无法验证存档

javascript - 如果更改路线, meteor 将停止订阅