admin管理员组文章数量:1025251
I am using using collection2 and autoform with one level nested schemas
Node = new Meteor.Collection('node',{
schema: new SimpleSchema({
content: {
type: String,
label: "Content",
max: 200
}
created: {
type: Date,
label: "Created Date"
},
modified: {
type: Date,
label: "Modified Date"
}
})
});
NodeMeta = new Meteor.Collection('Node_meta',{
schema: new SimpleSchema({
desc:{
type:String,
max:200,
label:"Description",
optional:true
}
})
});
Schema = {};
Schema.nodeWithMeta= new SimpleSchema({
Node: {
type: Node.simpleSchema()
},
Meta: {
type: NodeMeta.simpleSchema()
}
});
{{#autoForm schema=schema id="nodeForm" type="method" meteormethod="nodecreate"}}
{{> afFieldInput name='Node.content' rows=8 }}
{{> afFieldInput name='Meta.desc' rows=8}}
<button type="submit" class="btn btn-primary btn-submit">Create</button>
{{/autoForm}}
Template.nodeCreate.helpers({
schema: function() {
return Schema.nodeWithMeta;
}
});
It does not call server method. I tried autoform onSubmit hook as well as Meteors inbuilt templates 'submit' event handler. If I use jQuery onsubmit event handler, it registers the event. I cannot use jQuery for this purpose since autoform has to validate the inputs.
I am using using collection2 and autoform with one level nested schemas
Node = new Meteor.Collection('node',{
schema: new SimpleSchema({
content: {
type: String,
label: "Content",
max: 200
}
created: {
type: Date,
label: "Created Date"
},
modified: {
type: Date,
label: "Modified Date"
}
})
});
NodeMeta = new Meteor.Collection('Node_meta',{
schema: new SimpleSchema({
desc:{
type:String,
max:200,
label:"Description",
optional:true
}
})
});
Schema = {};
Schema.nodeWithMeta= new SimpleSchema({
Node: {
type: Node.simpleSchema()
},
Meta: {
type: NodeMeta.simpleSchema()
}
});
{{#autoForm schema=schema id="nodeForm" type="method" meteormethod="nodecreate"}}
{{> afFieldInput name='Node.content' rows=8 }}
{{> afFieldInput name='Meta.desc' rows=8}}
<button type="submit" class="btn btn-primary btn-submit">Create</button>
{{/autoForm}}
Template.nodeCreate.helpers({
schema: function() {
return Schema.nodeWithMeta;
}
});
It does not call server method. I tried autoform onSubmit hook as well as Meteors inbuilt templates 'submit' event handler. If I use jQuery onsubmit event handler, it registers the event. I cannot use jQuery for this purpose since autoform has to validate the inputs.
Share Improve this question asked Apr 18, 2014 at 14:59 Vailancio RodriguesVailancio Rodrigues 611 silver badge6 bronze badges2 Answers
Reset to default 3Since created
and modified
are required fields, it's most likely not submitting because those fields are missing from the form, which means the form is invalid. There are actually a few different ways you can solve this:
- Make them optional (probably not what you want)
- Use a different schema, one without those two fields, for the
schema
attribute of the autoform. - Add a "before method" hook that sets those two fields in the submitted doc.
- Use
autoValue
to generate the values for those two fields.
Since created and modified dates are fairly easy to do with autoValue, I would do it that way. Something like this:
created: {
type: Date,
label: "Created Date",
autoValue: function () {
if (this.isInsert) {
return new Date;
} else {
this.unset();
}
}
},
modified: {
type: Date,
label: "Modified Date",
autoValue: function () {
if (this.isInsert) {
this.unset();
} else {
return new Date;
}
}
}
Also, to help figure out issues like this more easily while developing, I remend enabling debug mode.
Have you allowed inserts/updates on your collection? See http://docs.meteor./#dataandsecurity.
I bet if you run the two mands below, it'll work.
meteor add insecure
meteor add autopublish
Now try your submit.
If it does work, turn autopublish and insecure back off
meteor remove insecure
meteor remove autopublish
Then write your allow methods, e.g.
Node.allow({
insert: function (userId, nodeDoc) {
// write some logic to allow the insert
return true;
}
});
I am using using collection2 and autoform with one level nested schemas
Node = new Meteor.Collection('node',{
schema: new SimpleSchema({
content: {
type: String,
label: "Content",
max: 200
}
created: {
type: Date,
label: "Created Date"
},
modified: {
type: Date,
label: "Modified Date"
}
})
});
NodeMeta = new Meteor.Collection('Node_meta',{
schema: new SimpleSchema({
desc:{
type:String,
max:200,
label:"Description",
optional:true
}
})
});
Schema = {};
Schema.nodeWithMeta= new SimpleSchema({
Node: {
type: Node.simpleSchema()
},
Meta: {
type: NodeMeta.simpleSchema()
}
});
{{#autoForm schema=schema id="nodeForm" type="method" meteormethod="nodecreate"}}
{{> afFieldInput name='Node.content' rows=8 }}
{{> afFieldInput name='Meta.desc' rows=8}}
<button type="submit" class="btn btn-primary btn-submit">Create</button>
{{/autoForm}}
Template.nodeCreate.helpers({
schema: function() {
return Schema.nodeWithMeta;
}
});
It does not call server method. I tried autoform onSubmit hook as well as Meteors inbuilt templates 'submit' event handler. If I use jQuery onsubmit event handler, it registers the event. I cannot use jQuery for this purpose since autoform has to validate the inputs.
I am using using collection2 and autoform with one level nested schemas
Node = new Meteor.Collection('node',{
schema: new SimpleSchema({
content: {
type: String,
label: "Content",
max: 200
}
created: {
type: Date,
label: "Created Date"
},
modified: {
type: Date,
label: "Modified Date"
}
})
});
NodeMeta = new Meteor.Collection('Node_meta',{
schema: new SimpleSchema({
desc:{
type:String,
max:200,
label:"Description",
optional:true
}
})
});
Schema = {};
Schema.nodeWithMeta= new SimpleSchema({
Node: {
type: Node.simpleSchema()
},
Meta: {
type: NodeMeta.simpleSchema()
}
});
{{#autoForm schema=schema id="nodeForm" type="method" meteormethod="nodecreate"}}
{{> afFieldInput name='Node.content' rows=8 }}
{{> afFieldInput name='Meta.desc' rows=8}}
<button type="submit" class="btn btn-primary btn-submit">Create</button>
{{/autoForm}}
Template.nodeCreate.helpers({
schema: function() {
return Schema.nodeWithMeta;
}
});
It does not call server method. I tried autoform onSubmit hook as well as Meteors inbuilt templates 'submit' event handler. If I use jQuery onsubmit event handler, it registers the event. I cannot use jQuery for this purpose since autoform has to validate the inputs.
Share Improve this question asked Apr 18, 2014 at 14:59 Vailancio RodriguesVailancio Rodrigues 611 silver badge6 bronze badges2 Answers
Reset to default 3Since created
and modified
are required fields, it's most likely not submitting because those fields are missing from the form, which means the form is invalid. There are actually a few different ways you can solve this:
- Make them optional (probably not what you want)
- Use a different schema, one without those two fields, for the
schema
attribute of the autoform. - Add a "before method" hook that sets those two fields in the submitted doc.
- Use
autoValue
to generate the values for those two fields.
Since created and modified dates are fairly easy to do with autoValue, I would do it that way. Something like this:
created: {
type: Date,
label: "Created Date",
autoValue: function () {
if (this.isInsert) {
return new Date;
} else {
this.unset();
}
}
},
modified: {
type: Date,
label: "Modified Date",
autoValue: function () {
if (this.isInsert) {
this.unset();
} else {
return new Date;
}
}
}
Also, to help figure out issues like this more easily while developing, I remend enabling debug mode.
Have you allowed inserts/updates on your collection? See http://docs.meteor./#dataandsecurity.
I bet if you run the two mands below, it'll work.
meteor add insecure
meteor add autopublish
Now try your submit.
If it does work, turn autopublish and insecure back off
meteor remove insecure
meteor remove autopublish
Then write your allow methods, e.g.
Node.allow({
insert: function (userId, nodeDoc) {
// write some logic to allow the insert
return true;
}
});
本文标签: javascriptMeteor Autoform package with collection2 does not submit the formStack Overflow
版权声明:本文标题:javascript - Meteor Autoform package with collection2 does not submit the form - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745615792a2159282.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论