Ways to create sub-form to be used as form array
I have
ItemForm
here

8 Replies
extended-salmonOPβ’5mo ago
And I want to create this
ItemForm
multiple time into array of form, but I also want to separate ItemForm
form. Here's roughly how I do it but I got typescript error (in the image)
Schema are
extended-salmonOPβ’5mo ago
nongtonkaew@gmail.com
StackBlitz
TansSack Form - Array of withForm - StackBlitz
The React framework for production
unwilling-turquoiseβ’5mo ago
the stackblitz is very helpful. I can fork it and adjust it to my approach if you'd like
the main conflict is that your form doesn't actually extend properly. your
ItemForm
expects type
to be set, but it's notunwilling-turquoiseβ’5mo ago
LeCarbonator
StackBlitz
TansSack Form - Array of withForm (forked) - StackBlitz
The React framework for production
unwilling-turquoiseβ’5mo ago
to summarize, you want to pass the index of the item's location into the item form component. That way, you can create a namespace of
events[index]
that gives you access to that subform's value
as for passing the form from one withForm to another, you can just use the top-level form given as prop in it
no need for field.form
Also note this handy trick for typescript:
Let me know if you have more questions!extended-salmonOPβ’5mo ago
Oh thank you for much ^_^ πββοΈ πββοΈ
So only way to use form composition is by have common fields right?, but nested form composition isn't possible?
unwilling-turquoiseβ’5mo ago
no, youβd need a whole new Api for that. Otherwise, calling setFieldValue would have to be able to know
however, if itβs guaranteed that you have the whole object, you can just handle state management on object level
extended-salmonOPβ’5mo ago
Thank you <3 πββοΈ πββοΈ