Use Flow Router Param in Autoform

Friends,

I’m working on my first app in Meteor and hitting my head against the wall on something…

I have a scenario similar to a blog + comments situation where I have one collection (call it ‘posts’) and want to associate documents from another collection (call it ‘comments’).

The best way I know to pass the post._id to the comments as a “postId” field is to use the Flow Router params, since the form is on the ‘post/:id’ view.

But for the life of me, I cannot figure out how to get “var postId = FlowRouter.getParam(‘postId’);” to pass to Autoform so it populates. I’ve tried adding it as a function in the schema, as a hook and as a hidden field in the form on the page (obviously don’t want to go that route).

Autoform is amazing and I want to use it, but may have to wire it up the hard way if I can’t get this darn value to populate.

Any ideas? I’ve been hitting my head against the wall on this for a couple of days now.

Thanks!

Hi @allenfuller - not sure if you ever figured this out.

If you’re using a schema to build your form (either with the autoform or quickform tags) then you can put it right in there.

For example:

campaignId: {
	type: String,
	autoform: {
		value: function() {
			return FlowRouter.getParam('campaignId');
		},
		type: "hidden"
	}
},
1 Like