簡體   English   中英

流星自動成型自定義驗證不起作用

[英]meteor autoform custom validation not reactive

我正在嘗試對customSchema中定義的字段使用自定義驗證功能,但是錯誤消息不會在該字段上呈現。

num: {
    type: Number,
    label: "Number",
    min: 1,
    decimal: false, // unnecessary as this is default for Number, but for future reference
    autoform: {
        group: "Info",
        defaultValue: function() {
            //@TODO - default to next number for logged in user
            return 5;
        }
    },
    custom: function () {
           Collection.simpleSchema().namedContext("addNumberForm").addInvalidKeys([{name: "num", type: "numNotUnique"}]);
    }
},

我已經為其定義了自定義錯誤消息

SimpleSchema.messages({numNotUnique: "This number has already been entered"});

當我提交表單時,我可以確認自定義函數已執行,但是該字段的UI中沒有任何更改指示錯誤。 我從SimpleSchema.debug = true;獲得的上下文名稱“ addNumberForm” SimpleSchema.debug = true; 設置並查看使用默認驗證向其他字段拋出的內容。

我在這里想念什么?

經過反復嘗試,我已經弄清楚了。

僅當使用simpleSchema本身進行手動驗證時,才有必要使用simpleSchema命名上下文。 Autoform會解決此問題,並且自定義函數可以返回定義錯誤的簡單字符串。

num: {
    type: Number,
    label: "Number",
    min: 1,
    decimal: false, // unnecessary as this is default for Number, but for future reference
    autoform: {
        group: "Info",
        defaultValue: function() {
            //@TODO - default to next number for logged in user
            return 5;
        }
    },
    custom: function () {
        // some check
        return 'numNotUnique'; // return our error
    }
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM