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


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:


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

essentially in your field config:

  autoform: {
    options: function () {
       return,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: