【发布时间】:2016-03-10 21:19:52
【问题描述】:
我想为我的CAS_Entry 集合创建一个表单,使用 Meteor 的 autoform 包。代码如下所示。我还添加了定义的钩子,不幸的是,其中只有beginSubmit 和before 被执行并且没有条目被添加到集合中。使用 Meteor shell,插入就像一个魅力。
感谢任何提示。
addCasEntry.html,表单展示模板:
{{#autoForm collection="CAS_Entry" type="insert" id="addCasEntryForm"}}
{{> afQuickField name="type" options="allowed"}}
{{> afQuickField name="description" rows="6" type="textarea"}}
{{> afQuickField name="file" type="cfs-file" collection="Images"}}
{{> afQuickField name="date" }}
<button type="submit" class="btn btn-primary">Add</button>
{{/autoForm}}
addCasEntry.js,添加调试钩子:
AutoForm.hooks({
addCasEntryForm: {
before: {
insert: function(doc) {
console.log(doc);
}
},
after: {
insert: function(error, result) {
console.log('Occured error: ' + error);
}
},
beginSubmit: function() {
console.log('begin submit');
},
onSuccess: function(formType, result) {
console.log("Insert succeeded");
console.log('Result ' + result);
},
onError: function(formType, error) {
console.log('Error!!!');
console.log(error);
}
}
});
SimpleSchema.debug = true;
/lib/collection/cas_entry.js:
CAS_Entry = new Mongo.Collection("cas_entries");
CAS_Entry.attachSchema(new SimpleSchema({
type: {
type: String,
allowedValues: ['reflection', 'evidence']
},
description: {
type: String,
optional: true
},
file: {
type: String,
optional: true,
},
timeUploaded: {
type: Date,
optional: true,
autoValue: function() {
return new Date();
}
},
date: {
type: Date,
}
}));
CAS_Entry.allow({
'insert': function() {
return true;
},
'update': function() {
return true;
}
});
这是控制台输出:
【问题讨论】:
-
您是否在表单中附加了架构?
-
我为集合附加了一个模式。因此,据我所知,autoform 应该默认使用它。这适用于我的其他表格。
-
是的,这就是我的意思。那么您是否尝试过调试选项来查看架构是否可能会过滤掉您的一些数据?
-
SimpleSchema.debug = true
标签: javascript meteor meteor-autoform meteor-collection2