I insert docs with my quickform
{{> quickForm id=id collection=collection type="method" meteormethod="createDoc"}}
but I also want to set userId
on all inserted docs.
I have the variable userId
in my template, so I wonder if I can just do something like
{{> quickForm id=id collection=collection type="method" meteormethod="createDoc" userId=userId}}
and use the passed variable in my server method?
You can add additional params in the autoform hooks:
Html
{{> quickForm id="idForm" collection=collection type="method" meteormethod="createDoc"}}
JS
AutoForm.hooks({
idForm: {
before: {
method: function(doc) {
doc.user = {}
doc.user._id = Meteor.user()._id;
doc.user.username = Meteor.user().username;
return doc;
}
},
onSuccess: function(formType, result) {
console.log(formType, result);
this.resetForm();
},
onError: function(formType, error) {
console.log(formType, error)
}
}
}
});
For more details, check this section of the documentation Callbacks/Hooks
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.