3

I have a collection of projects and the Meteor.users collection. My goal is to add the document _id of a project to a username.

HTML:

<template name="insertName">
    {{#each projectList}}
        {{> projectView}}
    {{/each}}
</template>

<template name="projectView">
    {{#autoForm collection="Meteor.users" id="insertUser" type="insert"}}
         {{> afQuickField name="username"}}
         // From here I can access the _id property from the projects collection
         // Question: How do I pass it to my form without creating an input field?
    {{/autoForm}}
</template>

JS:

Meteor.users = new Meteor.Collection('projects');
Meteor.users.attachSchema(new SimpleSchema({
    username: {
        type: String,
        max: 50
    },
    projectId: {
        type: String,
        max: 20
        // Use autoValue to retrieve _id from projects collection?
    }
});

Using the HTML code above, I know I could write this:

{{> afQuickField name='projectId' value=this._id}}

This, however, creates an input field, which I don't want. How can I pass the _id to my autoForm without having a visible input field? Or maybe someone can point me into a different direction?

Moritz Schmitz v. Hülst
  • 3,229
  • 4
  • 36
  • 63
  • Possible duplicate of [How to add user id information in the schema and also hide form autoforms?](http://stackoverflow.com/questions/33381963/how-to-add-user-id-information-in-the-schema-and-also-hide-form-autoforms) – challett Oct 31 '15 at 16:06

2 Answers2

4

There are multiple ways of attacking this problem, but basically, if you want a hidden field, you must set the type of the autoform field to hidden.

You could do either:

{{> afQuickField name='projectId' value=this._id type='hidden'}}

or do that on the schema itself

Meteor.users = new Meteor.Collection('projects');
Meteor.users.attachSchema(new SimpleSchema({
    username: {
        type: String,
        max: 50
    },
    projectId: {
        type: String,
        max: 20,
        autoform: {
          type: 'hidden'
        }
    }
});
Serkan Durusoy
  • 5,447
  • 2
  • 20
  • 39
1

Im not confident this is the best solution, but I have seen this as a way of side stepping the issue you are having:

{{> afQuickField name='projectId' value=this._id type='hidden'}}
Winston RIley
  • 482
  • 3
  • 8