Austin Gayler
Austin Gayler

Reputation: 4356

Meteor AutoForm: form with id "asdf" needs either "schema" or "collection" attribute

I have an autoform that I want to render using a schema. I have the schema returned by a helper template in Template.name.helpers({:

Template.name.helpers({
  getSchema: function() {
    var schema = new SimpleSchema({
      location: {
        type: String,
        label: "Start location"
      }
    });
    return schema;
  }

html:

{{#autoForm schema=getSchema id="submitOfferLift" type="method"}}

However I can't get the helper to work (relevant docs). In addition, if I just define schema = {...} in template.js and specify schema = "schema" in the autoform, I get a message saying that schema is not defined in the window scope. Furthermore, if I create the schema variable in the console, the form renders just fine.

Upvotes: 0

Views: 199

Answers (1)

Serkan Durusoy
Serkan Durusoy

Reputation: 5472

Your helper is returning a simple object whereas it should have been returning a SimpleSchema instance

Template.name.helpers({
  getSchema: function() {
    var schema = new SimpleSchema({
      location: {
        type: String,
        label: "Start location"
      })
      return schema;
  }
})

Also, the template inclusion should use > instead of #

{{> autoForm schema=getSchema id="submitOfferLift" type="method"}}

Upvotes: 1

Related Questions