Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use two different collection in one form using autoform & collection2 package in meteor?

I made one form using autoForm & collection2 package in meteor. I want to add one dropdown field to that form which option is populate based on another collection i have. can i do that way?

Any advice...

like image 417
iamhimadri Avatar asked Jan 23 '26 21:01

iamhimadri


1 Answers

You can use a template helper function to populate the options for the drop down. Define a function that returns an array of option objects, then set the options attribute of the select field to the name of the function.

Template.appInsert.helpers({
    getOptions:  function() {
        var cursor = YourCollection.find();
        return cursor.map(function(doc) {
            return {label: doc.name, value: doc._id};
        });
    }
});

Then use the helper function in your quick field definition:

{{>afQuickField name='fieldName' options=getOptions}}
like image 81
Brian Shamblen Avatar answered Jan 26 '26 17:01

Brian Shamblen