Is there an autoform solution for selecting child schema instances in an array field?


#1

I have a use case that I feel must be fairly common, but I’m not sure if this has been solved yet or not.

I have a ‘Monster’ schema:

 {
    "name": "Evil Enemy 1"
 }

and a Battle schema that has an array of monsters present for the battle:

{
    "name": "battle",
    "monsters": [Monster]
}

And in my UI, I would like the user to be able to select Monsters by name, but have the DBRefs populated in the monsters array on the backend. Essentially, I want an array of subschemas to represent a multi-select in generated forms, and this is definitely only one of many situations like this.

It seems like there must be a solution for something like this already implemented somewhere? Thanks for any pointers, or docs on where to look for starters on accomplishing this.

Similar question on StackOverflow: http://stackoverflow.com/questions/23644355/how-to-generate-a-form-to-select-a-user-using-autoform-and-collection2-in-meteor


#2

The answer on stack overflow seems to point you in the right direction.

essentially in your field config:

  autoform: {
    options: function () {
       return _.map(Collection.find().fetch(),function (element) {
         return {
           label: element.label, value: element._id
         };
       });
    }
  }

Then make sure the relevant details are published.

Sorry for any typos, my keyboard appears to be playing up :frowning: