Add/Delete fields in a form based on another field
Hi there!
I made a form with TanStack-Form / React (see video) where I manage the display of two extra fields if I select the "Good Til Time" option in my select list.
For the moment, the fields are flat and not nested, I just hide them and ignore their values in the submit, but it's not ideal.
I haven't found any examples of how to add nested fields properly (I see there's the possibility of manipulating indexes). But if anyone has managed to do an example, I'd love to 🙏🏽 .
Thanks a lot and have a nice day guys.
ps: the lib experience so far is great
3 Replies
ambitious-aqua•2y ago
Ahh, so you're talking about dynamic fields based on other fields?
Like "show A when B is set to this value"?
quickest-silver•2y ago
I think you'll just need to have some optional fields in your form, and display them with something like
{form.getFieldValue('timeInForce') === 'Good til time' && <OtherInputs />}
Then to be safe, in the form validation, you can make sure that those fields are provided when timeInForce is correctoptimistic-goldOP•2y ago
Yes exactly
Ok thanks, I'll give it a try 👌