简体   繁体   中英

meteor js (meteor-autoform + iron router) pass value after form is submitted

After a form is successfully validated I would like to redirect the user to a specific page and display some values. I don't know if the way I think to use is the correct one. Here's what I tried already:

creating form in template:

{{> quickForm collection="Transactions" id="insertTransaction" type="insert"}}

then I created the hook to get called when form is validated & inserted

AutoForm.addHooks('insertTransaction',{
  onSuccess: function(data){
    Router.go('one', null, {query: 'amount=' + data->amount});
    console.log(data);
  }
});

@Michel Floyd

my one.html

<template name="one">
<div class="row">
    <div class="col-sm-7">
       One Page...
    </div>
    <div class="col-sm-5">
        {{ amount }}
    </div>
</div>
</template>

My code from home.js (client/home.js):

AutoForm.addHooks('insertTransaction',{
onSuccess: function(data, data2, data3){

    result = Transactions.findOne(data2, { amount: 1});
    amount = (result["amount"]);
    Router.go('one',{amount: amount});
}
});

Here's my router code:

Router.route('/one/:amount',()=>{
name: 'one',
this.render('one', {data: this.params.amount});
});

I get "No route found named "one"" all the time.

First Create a route with amount as a param, ie

Router.route('/one/:amount',()=>{
  name: 'one',
  this.render('one', {data: this.params.amount});
});

Then use Router.go('one',{amount: amount});

Note that there's no underscore next to amount in this.params.amount

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM