What I am trying to do is create a form with meteor-autoform that will redirect the user to a newly generated route on submit. My thought process is that I can take the submissions _id and use it for an iron:router parameter. What I have so far looks as followed:
我想要做的是创建一个带有meteor-autoform的表单,该表单将用户重定向到提交时新生成的路由。我的思考过程是我可以提交_id并将其用作iron:router参数。到目前为止,我所看到的如下:
Creation of Form
创建表格
Submits = new Meteor.Collection('Submits');
Submits.allow({
insert: function(username, doc){
return !!username;
}
});
SubmitSchema = new SimpleSchema({
title: {
type: String,
label: "Title"
},
subject:{
type: String,
label: "Subject"
},
summary:{
type: String,
label: "Summary"
},
author:{
type: String,
label: "Author",
autoValue: function() {
return this.userId
},
autoform: {
type: "hidden"
}
},
createdAt: {
type: Date,
label: "Created At",
autoValue: function(){
return new Date()
},
autoform: {
type: "hidden"
}
}
});
Submits.attachSchema( SubmitSchema );
Routing
Router.route('/submit', {
layoutTemplate: 'submitLayout',
waitOn: function() { return Meteor.subscribe("Submits"); },
loadingTemplate: 'loading'
});
Router.route('/submit/:_id', {
name: 'formDisplay',
data: function() {
return Submits.findOne({this.params._id});
}
});
And then I just have the average publish and find calls. My issues are I'm not sure how to perform the redirect on submit, and I am not sure how to display the form results on the newly generated route.
然后我只有平均发布和查找电话。我的问题是我不知道如何在提交时执行重定向,我不知道如何在新生成的路由上显示表单结果。
Any help would be appreciated.
任何帮助,将不胜感激。
1 个解决方案
#1
0
I was able to do it by adding an autoform.hook and changing my routing a bit.
我能够通过添加autoform.hook并稍微更改我的路由来实现。
Autoform hook:
AutoForm.addHooks('insertSubmit', {
onSuccess: function(doc) {
Router.go('formDisplay',{_id: this.docId});
}
})
Routing:
Router.route('/submit/:_id', {
name: 'submitLayout',
data: function() { return Products.findOne(this.params._id);}
});
I got this information from this post:
我从这篇文章中得到了这些信息:
Route to the new data submitted by Meteor autoform using iron router?
使用铁路由器路由到Meteor autoform提交的新数据?
#1
0
I was able to do it by adding an autoform.hook and changing my routing a bit.
我能够通过添加autoform.hook并稍微更改我的路由来实现。
Autoform hook:
AutoForm.addHooks('insertSubmit', {
onSuccess: function(doc) {
Router.go('formDisplay',{_id: this.docId});
}
})
Routing:
Router.route('/submit/:_id', {
name: 'submitLayout',
data: function() { return Products.findOne(this.params._id);}
});
I got this information from this post:
我从这篇文章中得到了这些信息:
Route to the new data submitted by Meteor autoform using iron router?
使用铁路由器路由到Meteor autoform提交的新数据?