Route to the new data submitted by Meteor autoform using iron router?

前端 未结 3 1509
失恋的感觉
失恋的感觉 2020-12-19 04:44

I\'m using Meteor with AutoForm & Iron Router.

I have an autoform for inserting a data, and I want to redirect to the page of the data I added after a successful

相关标签:
3条回答
  • 2020-12-19 04:52

    The AutoForm hook will return you the docId. See: https://github.com/aldeed/meteor-autoform#callbackshooks

    this.docId: The _id attribute of the doc attached to the form, if there is one, or for an type='insert' form, the _id of the newly inserted doc, if one has been inserted.

    So use:

    Router.go('page',{_id: this.docId});
    
    0 讨论(0)
  • 2020-12-19 04:53
    onSuccess: function(formType, result) {
        Router.go(
            ['adminDashboard', result, 'Edit'].join(''), 
            {_id: this.docId}
        );
    },
    
    0 讨论(0)
  • 2020-12-19 05:01

    According to the doc on github, signatures changed: don't forget to declare the forms or null to apply the hooks.

    for all forms

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

    for specific form

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

    Best is to check the up to date signatures: https://github.com/aldeed/meteor-autoform#callbackshooks

    0 讨论(0)
提交回复
热议问题