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

I made one form using autoForm and collection2 in meteor. I want to add one dropdown field to that form which is populated based on another collection I have. can i do it?

Any advice ...

+3


source to share


1 answer


You can use the template helper function to populate the parameters for the dropdown. Define a function that returns an array of options objects, then set options

the select field attribute 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 a helper function in your quick definition definition:

{{>afQuickField name='fieldName' options=getOptions}}

      

+1


source







All Articles