2

Functions for select field choices cannot be read when inside an Array field

I can call a function to populate a select field's choices but when the same select field is inside an Array field I get TypeError: Cannot read property 'functionname' of undefined/

module.exports = {
  name: 'testtype',
  addFields: [
    {
      name: 'test_dynamic_select',
      type: 'select',
      choices: 'testchoice'
    },
    {
      name: 'insidearray',
      label: 'In Array',
      type: 'array',
      schema: [
        {
          name: 'test_dynamic_select_in_array',
          type: 'select',
          choices: 'testchoice'
        },
      ]
    }
  ],
  construct: function(self, options) {
    self.testchoice = async function(req) {
       var testarray = [
          {
            label: 'London',
            value: 'london'
          },
          {
            label: 'Edinburgh',
            value: 'edinburgh'
          },
          {
            label: 'Manchester',
            value: 'manchester'
          }
        ];

        return testarray;
    }
  }
}

The first select works (name: 'test_dynamic_select') The second one does not. (name: 'test_dynamic_select_in_array')

  • Sounds like a bug we need to fix. Most likely array fields aren't propagating the module property to their subfields. – Tom Boutell Jun 14 '19 at 14:40

1 Answers1

1

This was fixed in Apostrophe 2.92.1. You should run "npm update" and the problem should then be resolved.

Tom Boutell
  • 7,281
  • 1
  • 26
  • 23