corvid
corvid

Reputation: 11197

Submit url parameter with form to meteor method

I am using aldeed:autoform in order to render a form and run its result through a Meteor.method(). My form looks as follows:

SelectPlanTemplates = new SimpleSchema({
  templates: {
    type: [String],
    autoform: {
      options: function() {
        return PlanTemplates.find().map(function(doc) {
          return { label: doc.title, value: doc._id };
        });
      },
      noselect: true
    }
  },
  userId: {
    type: String,
    allowedValues: function() {
      return Meteor.users.find().map(function(doc) {
        return doc._id;
      });
    },
    autoform: {
      omit: true
    }
  }
});

On my template, I just do the following.

+ionContent
  +quickForm(schema="SelectPlanTemplates" id="SelectPlanTemplatesForm" type="method" meteormethod="createPlanFromTemplates")

My url is constructed like /plan/from_templates/{:userId}. I tried creating a hook to add the user id before submitting it.

AutoForm.hooks({
  SelectPlanTemplatesForm: {
    before: {
      method: function(doc) {
        doc.userId = Router.current().params.userId;
        return doc;
      }
    }
  }
});

However, it never seems to get to this hook.

How would I take a route parameter and pass it with my form to a meteor method with auto form?

Upvotes: 0

Views: 419

Answers (1)

corvid
corvid

Reputation: 11197

I think I figured out a little bit of a weird way of do it.

In the router:

this.route('selectPlans', {
  waitOn: function() {
    return Meteor.subscribe('plan_templates');
  },
  path: '/select/plan_templates/:_id',
  template: 'selectTemplates',
  data: function() {
    return new selectPlanTemplates({ userId: this.params._id });
  }
});

Then I added doc=this to my template

Upvotes: 0

Related Questions