How to pass a default value for a field in 'insert' form?
I'm using Meteor's packages: Autoform, Collections2, and Simple-Schema.
My process is:
Can't figure out how to pass a parameter withing URL (or any other way). The problem is how to initialize form with the value.
Suppose I have an URL:
http://localhost:3000/activity/new/Sport
=============== router.js:
...
Router.map(function () {
...
this.route('newActivity', {
path: '/activity/new/:tag',
data: function() {
Session.set('tag', this.params.tag);
return null;
}
});
...
=============== models/activity.js
...
Activities = new Meteor.Collection("activities", {
schema: {
title: {
type: String,
label: 'название'
},
...
tag: {
type: String,
label: 'тэг'
}
}
});
================ templates/avtibity.js
...
Template.newActivity.helpers({
defaultTag: function() {
return Session.get('tag');
}
});
...
================ templates/activity.html
...
<template name="newActivity">
<h1>Create new Activity!</h1>
{{#autoForm collection="Activities" id="insertActivityForm" type="insert"}}
{{> afQuickField name="title"}}
...
{{> afQuickField name="tag" value=" ?????? "}} // ? {{defaultTag}}
ho ho ho {{defaultTag}}
{{/autoForm}}
</template>
```
Thanks to Eric Dobbertin: