How to correctly handle related/ linked/ dependent or conditional fields? #621
Unanswered
Mushroomator
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In my form I have a checkbox which when checked copies over a value from an input field to another textarea and disables this textarea. Alternatively, if the checkbox is not checked I want the user to be able to fill in all those form fields on his own. So basically I have form fields which have dependencies to each other and I need to set other form fields in the
onChange
callback of a form field.I haven't really found any documentation on this but after some fiddling around I found some solutions, some of which are obviously hacks but one seems to be a reasonable way to do things. This way involves
<form.Subscribe />
. It still seems a bit verbose though, so I am wondering whether there is a better solution or whether that's exactly<form.Subscribe />
was intended to do?Sample using
<form.Subscribe />
Output
PS
Without using
<form.Subscribe>
dependent fields never re-render. Another - obviously hacky - solution, which also seems to work though, is to usefield.form.getFieldInfo("description").instance?.handleChange("newValue");
to triggerhandleChange()
of the dependent property which let's it re-render.Beta Was this translation helpful? Give feedback.
All reactions