Form composition create reusable component using withForm
I want to create an Address Component that can be included in other forms. This component should just extend the existing form values with the address values:
However I cannot get the form to work as expected. The Fields render correctly but when I fill in the inputs, the SubmitButton does not think the input is valid (SubmitButton is the same as in docs).
5 Replies
fair-rose•5mo ago
withForm
requires the values and validators to align with the form you want to use it in
so extending any form that satisfies withForm
is not supported (yet)xenial-blackOP•5mo ago
is there any other way to create such a component then?
fair-rose•5mo ago
you sacrifice some type safety, but at the moment, this is a solution you can go for https://github.com/TanStack/form/discussions/1200#discussioncomment-12363833
GitHub
Compose forms with nested form structure · TanStack form · Discus...
The new createFormHook looks great but it appears that it only works when there's a shared data structure between the child and parent forms. The use case where this applies is when you have a ...
fair-rose•5mo ago
either that or you create a composite field (a field that manages state as
AddressObject
instead of multiple values)xenial-blackOP•5mo ago
Thank you very much 👍 This should be a reasonable workaround for now.