meteor - How to get dropdown option in schema using autoform? -


i want dropdown options collection (i.e mycollection). in collection have option values (i.e options). using collection2 package want options in schema not using helper.

define collection :

mycollection = new mongo.collection('mycollection'); 

collection structure :

{     options : [a, b, c, d, e, f] } 

collection2 schema :

some-schema = new simpleschema({       dropdown : {          type : string,          label : "select one",          autoform : {                options: /*....*/          }      } }); 

html :

{{#autoform schema='some-schema' id='some-id' type="method" meteormethod="some-method"}}     {{> afquickfield name='dropdown'}} {{/autoform}} 

any suggestion...

you can use function executed in reactive computation dynamically compute list of available options.

someschema = new simpleschema({   [...]   dropdown : {     type : string,     label : "select one",     autoform : {       options: function(){         var doc = mycollection.findone();         var docoptions = doc && doc.options;         return _.map(docoptions, function(value){           return {             label: value,             value: value           };         });       }     }   }   [...] }); 

you can set options in autoform select using many different ways, see : https://github.com/aldeed/meteor-autoform#what-are-the-various-ways-i-can-specify-options-for-a-select-radio-group-or-checkbox-group


Comments