I need to set some default values to a multi select field with custom options. I am currently fetching data from an API and setting the values in the options field (which is working great).
multiSelectField.options = response.map((resp) => (
{label: resp.label, value: resp.value}
)); // This works as expected
However, I am not able to set the default values (the select field should be populated once the data is fetched from the API).
I have tried the following two methods (considering that React-Select is used):
- Using the
value
attribute:
multiSelectField.value = [{ label: "Default Option 1", value: "Default Option 1" }]
- Using the
defaultValue
attribute -
multiSelectField.defaultValue = [{ label: "Default Option 1", value: "Default Option 1" }]
However, still the multi select field does not have the data populated by default when the page is refreshed. Looked over the documentation, but couldn’t find any specific articles regarding this case.
Any leads or suggestions are highly appreciated.