issue: isValid state does not work in Stepper form #8787
-
Version Number6.14.0 but also seen on 7.33.0 Codesandbox/Expo snackhttps://codesandbox.io/s/heuristic-lehmann-df6hmw Steps to reproduceHello, I'm having this problem with isValid state when using react-hook-form on a stepper. The state of isValid seems a bit messed up when we use a back button. For example, if first step is valid and you go on to the next, trigger an error and go back, isValid will be false even though the first step is still valid. This is a problem because I would like to use isValid as the state for the 'next' button to be disabled or not. Is there any suggestions how to get this working or is it a bug? Or is there another suggestion for what variable to use to disable the button?
Expected behaviourisValid should match the valid state of current step What browsers are you seeing the problem on?Chrome Relevant log outputNo response Code of Conduct
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
RHF works correct in your use-case. You trigger the second step validation by clicking "Next", but going back via "Back" button, you only update the form's step, but not the form validation state. Hence, the form's Validation state is not being updated because your "change" your validation schema; the validation process is not triggered by it. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your answer. Is there any suggestion how to use isValid on a stepper? If I try to manually trigger it when user goes back, it initially works but then eventually goes out of sync again when you go forward - then the button will not be grayed out when you go forward again. |
Beta Was this translation helpful? Give feedback.
-
Little bit tricky suggestion, but it should work. Just add a "dummy" input to the every single step: <input
key={stepId}
type={'hidden'}
{...register(`stepId-${stepId}`, {
shouldUnregister: true
})}
/> Notice that there is |
Beta Was this translation helpful? Give feedback.
-
Hello ! i found a better way to fix this issue, and avoid "dummy" inputs, use
|
Beta Was this translation helpful? Give feedback.
Little bit tricky suggestion, but it should work.
Just add a "dummy" input to the every single step:
Notice that there is
shouldUnregister
option provided