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");
可否请你提供一个信息库? –