How to dynamically change the component value based on the value of other component? #1066
-
I am having a use case that I need to change the selected value of a Select component based on the value of other component. I tried the resolveProps and it works on other props (like isDisabled, or even options) rather than value. In the doc, it mentions input.onChange can be used in this case. However, I cannot see input.onChange exists. I know that I can use the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello, in this case, I would create a new component or enhance the current select.
I have this component implemented in one of my forms: https://github.com/RedHatInsights/sources-ui/blob/master/src/components/AddApplication/AuthTypeSetter.js It changes authentication value according to selectedAuthentication. |
Beta Was this translation helpful? Give feedback.
Hello,
in this case, I would create a new component or enhance the current select.
Wrap it with
FormSpy
and setsubscription={{values: true}}
or set the form subscription for values. This ensures that the component will be always rendered when some value is changed.Use
formOptions
to get change function and use this function inuseEffect
hook when you need it.I have this component implemented in one of my forms: https://github.com/RedHatInsights/sources-ui/blob/master/src/components/AddApplication/AuthTypeSetter.js It changes authentication value according to selectedAuthentication.