Autoform: can I specify a helper parameter in the schema?

Is there a way to specify an auxiliary parameter in the schema? I tried:

Scheme

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

But that does not work.

The following method works fine to display a selection with parameters in the form:

Scheme

 { favoriteColor: { type: String } } 

Assistant

 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 real scheme, I have an array of objects, and in each object I need to select an element from another collection. When you use afArrayField, you can no longer set parameters in the template, as it was in the above template (because it is an array of objects, and one element in the object will refer to the helper).

Am I the only option to query the database when I define the schema? I think that will make it non-reactive, right?

+5
source share
1 answer
 { favoriteColor: { type: String, autoform: { options: function () { return Colors.find().map(function (c) { return {label: c.name, value: c._id}; }); } } } } 

Inserting a helper function directly into the circuit will work. I am doing something similar and it is reactive.

+5
source

Source: https://habr.com/ru/post/1212522/


All Articles