6
我有以下SimpleSchema我試圖添加自定義驗證來驗證輸入重複的客戶名稱,但是每當我嘗試保存新客戶時,我會收到錯誤:流星使用namedContext將addInvalidKeys添加到AutoForm窗體返回錯誤
Exception in delivering result of invoking 'adminCheckNewCustomerName': TypeError: Cannot read property 'namedContext' of null
有人可以告訴我我在做什麼錯誤/錯過這裏驗證客戶名稱對重複記錄嗎?由於
schema.js:
AdminSection.schemas.customer = new SimpleSchema({
CustomerName: {
type: String,
label: "Customer Name",
unique: true,
custom: function() {
if (Meteor.isClient && this.isSet) {
Meteor.call("adminCheckNewCustomerName", this.value, function(error, result) {
if (result) {
Customer.simpleSchema().namedContext("newCustomerForm").addInvalidKeys([{
name: "CustomerName",
type: "notUnique"
}]);
}
});
}
}
}
});
UI.registerHelper('AdminSchemas', function() {
return AdminSection.schemas;
});
form.html:
{{#autoForm id="newCustomerForm" schema=AdminSchemas.customer validation="submit" type="method" meteormethod="adminNewCustomer"}}
{{>afQuickField name="CustomerName"}}
<button type="submit" class="btn btn-primary">Save Customer</button>
{{/autoForm}}
collections.js:
this.Customer = new Mongo.Collection("customers");
可否請你提供一個信息庫? –