Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autoform: can I specify the options helper in the schema?

Is there any way to specify the options helper in the schema? I tried:

Schema

{
  favoriteColor: {
    type: String,
    autoform: {
      options: "colorOptions"
    }
  }
}

But it does not seem to work.

The following technique works fine to display a select with options in a form:

Schema

{
  favoriteColor: {
    type: String
  }
}

Helper

Template.myFormTemplate.helpers({
  colorOptions: function () {
    return Colors.find().map(function (c) {
      return {label: c.name, value: c._id};
    });
  }
});

Template

{{> afQuickField name="favoriteColor" options=colorOptions}}

In my actual schema I have an array of objects, and in each object I need to select an item from different collection. When you use afArrayField you can no longer set the options in the template as I did in the Template above (because it's an array of objects, and one element in the object would refer the helper).

Is my only option to query the database when I define the scheme? That I guess would make it non reactive, right?

like image 835
aBe Avatar asked Feb 03 '15 11:02

aBe


1 Answers

{
  favoriteColor: {
    type: String,
    autoform: {
      options: function () {
    return Colors.find().map(function (c) {
      return {label: c.name, value: c._id};
    });
  }
    }
  }
}

Inserting the helper function directly into the schema will work. I'm doing something similar and it is reactive.

like image 196
Jeremy Plack Avatar answered Nov 04 '22 01:11

Jeremy Plack