0

I am reproducing a simplified version of my problem, to ask a fundamental question.

I have a template called 'form',

<template name="form">
    <input id="name" type="text">
    <button id="submitform type="submit">Submit</button>
</template>

I am handling the submit event as follows,

Template.form.events({
    'click #submitform': function() {
        event.preventDefault();
        if(Meteor.user())
            alert('submitted');
        else{
            //save the filled form along with view (basically the template or view)
            Router.go('login');
        }
    }
});

My question is, how do i save the filled template with data filled in a variable/any how, so that i can render it after sign in. This is how I am rendering to form template,

Router.route('/form', function () {
  this.render('form');
});    

What I want is to be able to render the user filled template/view back for him when he signs in. Please tell if there is a meteor way of doing it, and not easy JavaScript hack. Please ask if you need additional data/code. Thanks in advance.

2 Answers2

0

You can use a session variable for this if I'm understanding your question.

<template name="form">
    <input id="name" type="text" value="{{name}}">
    <button id="submitform type="submit">Submit</button>
</template>

Template.form.helpers({
    name() {
        return Session.get('name');
    }
});

Template.form.events({
    'click #submitform': function(event, template) {
        event.preventDefault();
        if(Meteor.user())
            alert('submitted');
        else{
            Session.set('name', template.find('#name').value);
            Router.go('login');
        }
    }
});

Then on your Meteor.loginWithPassword callback redirect back to the form route.

Stephen Woods
  • 4,049
  • 1
  • 16
  • 27
0

If you want to save the form with the user data in it, you could you make it invisible and then visible again later when you want to show it?

Otherwise you could repopulate the form from a save formData object. See Use jquery to re-populate form with JSON data

Community
  • 1
  • 1
Rune Jeppesen
  • 1,121
  • 13
  • 22