How to come back to specific step and set errors? #122
-
|
Hi, first of all thanks for this well written library, it really helps to manage the form step states 🚀 So, in my use case when we finish the form steps and send the data to an API, the API could return us an array of field errors with a proper error message like: my question is, is there an easy way or any good pratices to return to the specific step and use the react-hook-form to set the form error since the form structure with stepperize is written in a composed-like architectury? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
|
Hi! Thank you very much and I'm glad you're enjoying the library. Regarding your use case, you could use the before/after methods which allow for asynchrony so that you can call your API and then decide whether you want to continue with the next step or go back to a previous one. And if you need to store that error somewhere in order to work on parent components that contain the react-hook-form hook, then you can make use of the metadata API to store that error and then access it from the step where you need to handle the error. I think this will solve your problem. If not, send me a codesandbox or reproducible example so I can help you further. |
Beta Was this translation helpful? Give feedback.
-
|
Came back a few hours later and kinda find out an way to do it (a little gross right now but it is working) https://codesandbox.io/p/github/RafaelAndeloci/form-step-example/ |
Beta Was this translation helpful? Give feedback.
Came back a few hours later and kinda find out an way to do it (a little gross right now but it is working)
https://codesandbox.io/p/github/RafaelAndeloci/form-step-example/