formio / formio.js

JavaScript powered Forms with JSON Form Builder
https://formio.github.io/formio.js
MIT License
1.83k stars 1.04k forks source link

FIO-8091: added selectData calculation for url/resource select components #5564

Closed roma-formio closed 2 months ago

roma-formio commented 2 months ago

Link to Jira Ticket

https://formio.atlassian.net/browse/FIO-8091

Description

The issue: possible select component configuration: URL/Resource data source, lazy loading, value property and item template (using different properties from request object), default value. With this configuration in the form definition, we can see only value property for default value. So select component will be not aware of other object properties unless click on the select component to load items. The solution: add selectData property for select component definition so select component can use required data for template without loading items.

The first iteration: I tried to use just conditional and calculated value for the selectData field but faced a problem when we change the template and click on default value to load items, as a result, calculate will not be triggered because the default value will not be changed. Second iteration: when we click on the default value field, we're loading all items, and the onSetItem method will be called so we can use it to update the selectData property and do the same when we select other default values using the onChange method. Set selectData with all additional fields that the select component needs using a template and loaded data.

How has this PR been tested?

Unit tests

Checklist: