1
votes

I have a template with an update Autoform:

<template name = "editLocationPage">
    <div class="flow-text">
      {{#if Template.subscriptionsReady}}
      <div>
      <br>
      {{#autoForm collection="Locations" doc=currentDoc id="editLocationPage" type="update"}}
         <fieldset>
           {{testDoc}}
           <legend>Edit Location / Asset</legend>
           {{> afQuickField name='id'}}
           {{> afQuickField name='text'}}
           {{> afQuickField name='description' rows=3}}
           {{> afQuickField name='type'}}
           {{> afQuickField name='parent'}}
         </fieldset>
         <button type="submit" class="btn waves-effect waves-light">Submit</button>
         <button type="reset" class="btn waves-effect waves-light red">Reset</button>
       {{/autoForm}}
     </div>
     {{/if}}
    </div>
</template>

Some helpers to subscribe and pass the doc to the template:

Template.editLocationPage.onCreated(function() {
  var self = this;
   self.autorun(function() {
     self.subscribe('singleLocation', Session.get("idTreeView").toString());
   });
});

Template.editLocationPage.helpers({
  currentDoc: function() {
    return Locations.find({"id":Session.get("idTreeView").toString()}).fetch()[0];
  }
});

A schema:

// Data subset subscribed to on client
Meteor.publish('locations', function() {
  return Locations.find({}, {fields: {
    text: true,
    id: true,
    type:true,
    parent:true
  }});
});

Meteor.publish('singleLocation', function(locationId) {
  return Locations.find({id:locationId});
});

The document is ok (findOne returns a valid doc) but the form does not work. Any ideas?

1
Any errors in the console? - Bjørn Bråthen
debug.js:41 Exception in template helper: TypeError: Cannot read property 'label' of undefined at Object.afFieldInputContext (localhost:3000/packages/…) at bindDataContext (localhost:3000/packages/…) ............ Followed by pages of exceptions - Goosey
Also tried passing this instead with no luck: Locations.find({"id":Session.get("idTreeView").toString()}).fetch()[0] - Goosey

1 Answers

0
votes

I just found the problem. I needed to add the schema:

{{#autoForm schema=locationFormSchema id="editLocationPage" type="update" collection=Locations doc=currentDoc}}

with a helper:

Template.editLocationPage.helpers({
  currentDoc: function() {
    return Locations.findOne({"id":Session.get("idTreeView").toString()});
  },
  locationFormSchema: function() {
    return Schema.locations;
  }
});