data-driven-forms / react-forms

React library for rendering forms.
https://data-driven-forms.org/
Apache License 2.0
302 stars 87 forks source link

Allow `set` condition attribute to be a function #1326

Closed Hyperkid123 closed 2 years ago

Hyperkid123 commented 2 years ago

Hi, before my question I want to thank you for your great library and your efforts to support and keep it updated.

I have a custom field array which its default values are set from other components based on some conditions. For example, in this sandbox, it is based on the text field if the value given is '3'. It works fine if I want to set/replace the whole field array with a given value but how can I append to it?

in the example provided, the field array initial values are 1 -> one and 2 -> two or whatever user type, and I want to append the 3->three if I write 3 in the text field, how can I achieve this?

Code Exaple: codesandbox

Thanks

Originally posted by @Ali-Zmn in https://github.com/data-driven-forms/react-forms/discussions/1319

Required format:

The set attribute should be either an object or a function that returns desired object.

type set = object | (formApi: FormApi) => object

Function result should be extracted here and added to the state: https://github.com/data-driven-forms/react-forms/blob/master/packages/react-form-renderer/src/condition/condition.js#L48

rvsia commented 2 years ago

:tada: This issue has been resolved in version 3.19.0 :tada:

The release is available on

Data-Driven-Forms.org!