3

In FormioJS Select there is data.custom option: "Valid JavaScript which will set a values object which is the values used to populate the select list." https://github.com/formio/formio.js/wiki/Select-Component

Call to function works, setting values does not. I tried code below, always getting [] as data in select itself:

const getModels = (values, m) => {
   console.log(values, m);
   values = [{label: ..., value: ...}, {etc}];
return values;
};

and form data is:

                {
                  type: 'select',
                  label: 'Manufacturer',
                  key: 'manufacturer',
                  placeholder: 'Select your manufacturer',
                  data: { values: allmanufacturers },
                  defaultValue: ''
                },
                {
                  type: 'select',
                  label: 'Model',
                  key: 'model',
                  placeholder: 'Select your model',
                  refreshOn: 'manufacturer',
                  dataSrc: 'custom',
                  data: { custom: 'getModels(values, data.manufacturer)' },
                  selectValues: 'Results'
                },

1 Answers1

2

For choicesjs widget, You can try set it via setItems method of :

data: { custom : "instance.setItems(getModels(values, data.manufacturer),true)" }