2014-10-10 62 views
9

我正在使用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掛鉤。任何指針在這裏讚賞

回答

17

經過大量的搜索後,事實證明,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

3

我沒有足夠的評論聲望,但根據documentation,似乎Autoform.addHooks現在採用formId。

那麼您會在自動窗體使用

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