Search code examples
meteormeteor-autoform

Form doesn't get individual form ID


I have an {{each}} statement which is suppose to have a form in. I can't figure out why the form doesn't use the forms unique _id. Any suggestions?

Path: helper.js

Template.Offer.helpers({
    jobOffers: function () {
        return JobOffers.find({candidateUserId: Meteor.userId()});
    }, 
    makeUniqueID: function () {
      return this._id;
    }
});

Path: template.html

{{#each jobOffers}}
    {{#autoForm collection="JobOffers" id="makeUniqueID" doc=this type="update"}}
        {{> afQuickField name='offer'}}
        <button type="submit" class="btn btn-primary submit">Update</button>
    {{/autoForm}}   
{{/each}}

Solution

  • With

    id="makeUniqueId"
    

    you make the form have id equal to exactly the string "makeUniqueId". To generate new IDs, omit quotes:

    id=makeUniqueId
    

    This will tell Spacebars to evaluate the function that stays behind the makeUniqueId helper, therefore supplying the autoForm template with proper value for id parameter.