Using Autoform array field to create just one multiselect (not one for each element)

So I have the following keys in my SimpleSchema:

  "profile.otherLocations": {
    type: Array,
    label: "Other Locations",
    autoform: {
      afFieldInput: {
        type: "other-location-select",
        multiple: "multiple",
        companySelectId: "employeeProfileEditCompanySelect",
        filterBy: "otherLocations"
        }
    }
  },
  "profile.otherLocations.$": {
    type: String,
    label: "Id",
  },

Based on the above, the template will create the “Other Locations” section on the page, but inside of that, a textfield is rendered for each element in the array returned from the database (which is expected, since it is an array of Strings). However, if I try and remove the autoform:{…} that is in the top-level field, and put it into the array element field, I was able to write some client-side JS in the autorun() to manually set the first field so it looks like this:


where the first multiselect is what I want (all array elements represented in a single “multiple” dropdown), but it insists on creating multiselects for each of the elements in the array. So if the profile.otherLocations array in mongoDB has a length of 12, it will create 11 additional empty selects like you see above. I just want all array elements (strings) to be represented in one multiselect field.

What would be the best way to prevent the additional select fields from being created? Alternately, is there any easier way to do this using ‘select2’? Have been stuck on this for almost a week, could definitely use advice.

yes easier to do with select2 autoform package
aldeed:autoform-select2

Could you give a brief example of what that might look like? I’ve been trying to find select2 options to do this with no luck so far.

Please check the link I have mentioned for the package, it has good example

@bbotezat as I saw you are using a custom extension other-location-select. Can you plase share it’s code? Setting a custom for type Array requires usually a total different approach than the usual one for single fields.