[英]Dynamic form generalion and removal using meteor and Aldeed's autoform
[英]Meteor using namedContext to addInvalidKeys to an AutoForm form returning an error
我有以下SimpleSchema,我试图添加自定义验证以验证输入重复的客户名称,但每当我尝试保存新客户时,我收到错误:
提供调用'adminCheckNewCustomerName'结果的异常:TypeError:无法读取null的'namedContext'属性
有人可以请告诉我我在做错了什么/在这里缺少来验证客户名称是否有重复记录? 谢谢
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");
检查collection2代码以获取附加到集合的模式:
_.each([Mongo.Collection, LocalCollection], function (obj) {
obj.prototype.simpleSchema = function () {
var self = this;
return self._c2 ? self._c2._simpleSchema : null;
};
});
这个神秘的谐音_c2
(编程中的两个难题之一......)来自attachSchema
:
self._c2 = self._c2 || {};
//After having merged the schema with the previous one if necessary
self._c2._simpleSchema = ss;
这意味着您忘记了attachSchema
或摆弄了收藏品的属性。
要解决:
Customer.attachSchema(AdminSchemas.customer);
//Also unless this collection stores only one customer its variable name should be plural
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.