Hello Retool community,
How can I set the value of a Multiselect component when the value comes from a database?
I have a form that includes a Multiselect component with a data source from tbl_countries
. I'm storing this form’s data in a table called tbl_datasources
, and another table called tbl_datasource_countries
stores the selected countries.
This is my table design:
**tbl_countries**
|id | code | name|
|--- | --- | ---|
|277 | US | United States of America|
|278 | GB | United Kingdom|
|279 | CA | Canada|
**tbl_datasources**
|id | code | name|
|--- | --- | ---|
|6 | EFX | Equifax|
|7 | TU | TransUnion|
**tbl_datasource_countries**
|id | datasource_id | country_id|
|--- | --- | ---|
|1 | 6 | 277|
|2 | 6 | 279|
The form automatically sets the values using {{ tableDatasources.selectedRow }}
, but this doesn’t seem to work with the Multiselect component that uses array values.
As a workaround, I temporarily added a button that sets the value of the Multiselect component when clicked.
I'm considering adding a custom script or event handler to automatically set the values for the country and region Multiselect components when I open the form, but are there other better ways to achieve this?
Thank you!