I am using https://github.com/aldeed/meteor-autoform for one of my meteor collections. I am using quickForm and type insert. Here is the relevant code:
<template name="postInsert">
<legend>Add your story here</legend>
{{> quickForm collection="Posts" id="insertPostForm" type="insert" buttonContent="Post!" resetOnSuccess=true}}
</template>
This form submits and creates the post successfully. But it doesn't display a success message. I know I can use the onSuccess hooks and write my own success message. But I was wondering if there is a standard way to display success message using an autoform configuration?
I looked through the documentation on github and searched a bit, but all solutions point to using the onSuccess hooks. Any pointers here are appreciated
After extensive search it turns out, onSuccess hooks ARE the standard way to display a success message. Here is my implementation of the same for completeness and for anyone else who might stumble upon this question in the future.
NEW Autoform 6.0.0
onSuccess: function(formType, result) {
FlashMessages.sendSuccess('Success!');
Router.go("/posts");
},
OLD
AutoForm.addHooks(['postInsert', 'postUpdate'], {
onSuccess: function(operation, result, template) {
FlashMessages.sendSuccess('Success!');
Router.go("/posts");
}
});
The use of AutoForm.addHooks keeps the code DRY allowing reuse for update as well as insert operations.
Also I am using the excellent flash-messages to display all my user messages. Highly recommended.
I don't have enough reputation to comment, but according to the documentation, it seems Autoform.addHooks now takes the formId.
So you would bind your autoform with id 'insertPostForm' using
AutoForm.addHooks(['insertPostForm'], {
onSuccess: function (operation, result, template) {
...
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With