简体   繁体   中英

Issues with dynamic routing using meteor-autoform and iron:router

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:

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.

I was able to do it by adding an autoform.hook and changing my routing a bit.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM