如何在流星中使用autoform显示成功消息?

问题描述:

我正在使用https://github.com/aldeed/meteor-autoform作为我的一个流星收藏。我正在使用quickForm和类型插入。以下是相关代码:如何在流星中使用autoform显示成功消息?

<template name="postInsert"> 
    <legend>Add your story here</legend> 
    {{> quickForm collection="Posts" id="insertPostForm" type="insert" buttonContent="Post!" resetOnSuccess=true}} 
</template> 

此表单成功提交并创建了该帖子。但它不显示成功消息。我知道我可以使用onSuccess挂钩并编写我自己的成功消息。但我想知道是否有一个标准的方式来显示使用autoform配置成功消息?

我查看了github上的文档并搜索了一下,但所有解决方案都指向使用onSuccess挂钩。任何指针在这里赞赏

经过大量的搜索后,事实证明,onSuccess挂钩是显示成功消息的标准方式。以下是我对完整性以及将来可能遇到此问题的任何其他人的执行情况。

新的自动窗体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"); 
    } 
}); 

采用AutoForm.addHooks保持代码的DRY允许更新重用以及作为插入操作。

此外,我使用优秀的flash-messages来显示我所有的用户信息。强烈推荐。

+0

感谢您回答问题(y) – dalgard 2015-01-22 20:40:11

+0

此代码位置在哪里特德?我似乎无法获得任何运行客户端的东西。另外,是'postInsert'你的模板名称?谢谢 – DeBraid 2015-05-05 12:43:29

+0

更新:代码运行客户端,是的,传递给'addHooks'的数组包含表单所在的模板名称。 :D原来我使用了错误的模板名称(文档不清楚) – DeBraid 2015-05-05 12:49:53

我没有足够的评论声望,但根据documentation,似乎Autoform.addHooks现在采用formId。

那么您会在自动窗体使用

AutoForm.addHooks(['insertPostForm'], { 
    onSuccess: function (operation, result, template) { 
       ... 
    } 
}); 

ID 'insertPostForm' 绑定据GitHub上的文档,签名更改为的onSuccess钩

AutoForm.addHooks(['yourForm'],{ 
    onSuccess: function(formType, result) { 
     Router.go('page',{_id: this.docId}); 
    } 
}); 

最好是检查了到目前为止签名:https://github.com/aldeed/meteor-autoform#callbackshooks