Multiple (dynamic forms) #7221
Replies: 8 comments 5 replies
-
you could break each form into its own component and haveing useForm at each one of them. |
Beta Was this translation helpful? Give feedback.
-
I am trying to create a multi-step form wizard where is each form will be submitted when I click the "Next" button. The issue is this submit button is outside of the forms. I want to submit individual forms with a single button separately. If I use FormProvider with form validations defined, it will validate everything on the form submission but some values don't need to be validated unless I go into the next step. Any solutions for this? |
Beta Was this translation helpful? Give feedback.
-
Any update to this issue? |
Beta Was this translation helpful? Give feedback.
-
Hi guys, I was also looking into something similar, then I stumbled upon this and this I am now giving it a go using MUI Stepper, let me know if it works for you so you can share your solutions with me. Thanks |
Beta Was this translation helpful? Give feedback.
-
I was able to solve this problem, but unfortunately I wasn't able to use react-hook-form because it gave me too many headaches and 2 sleepless nights. I decided to just use useState, and will now look into adding custom validation. What I ended up doing was:
My plan is to now add validation in the handleNext/HandleBack functions, and also a delete function to remove steps. Finally, the submit button will get the aggregate values from the orders object. Am sure there could be some cleaner ways to use the buttons and validation, but I am not an expert yet, and I have little time. I will refactor the code in time, but at least, this nightmare is over. here is the codesandbox, maybe someone can help integrate react-hook-form and Yup and share the complete solution |
Beta Was this translation helpful? Give feedback.
-
Hi folks, I have a similar issue and was wondering if we have any updates on this? |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, @robbertrosario @ninaboaventura @ashik112 @Moshyfawn I was able to solve my problem by creating a context using the react context API. I've created a repository with an example. Just to summarize: 1 - You can create a new context. 2 - You can then initialise multiple instances of useForm and assign to the context like I did here. 3 - Finally any component inside the context can access any of the forms by doing something like what I did here Let me know if this helps |
Beta Was this translation helpful? Give feedback.
-
I had same problem, where I had to show multiple independent forms on the same page to be opened based on some conditions, some as sub-forms. The problem was seen when we submit one form, another form in dom used to get submitted.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey,
I am currently working on a project which consists of different (dynamic) sections and each section contains multiple inputs (which are also dynamic) at the moment this is one giant form. But the downside to this is that in every section you also submit the others you've touched. So I am looking for a way to create multiple forms without knowing the exact amount.
Something like this wouldn't work
Because in my case I have so many different sections and forms and don't know the exact amount because they are dynamically rendered.
Does anyone know what the proper way to solve this would be?
Beta Was this translation helpful? Give feedback.
All reactions