我有以下 SimpleSchema,我正在尝试添加自定义验证以验证是否输入重复的客户名称,但每当我尝试保存新客户时,我都会收到错误:
传递调用“adminCheckNewCustomerName”的结果时出现异常:TypeError:无法读取 null 的属性“namedContext”
有人可以告诉我我做错了什么/在这里遗漏了以验证客户名称与重复记录吗?谢谢
架构.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;
});
表单.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}}
集合.js:
this.Customer = new Mongo.Collection("customers");