Replies: 3 comments
-
In theory, this is supposed to work at least with react-hook-form, by keeping the submitted values when const {
register,
handleSubmit,
reset,
formState: { errors, isDirty, isSubmitSuccessful },
} = useRemixForm<Inputs>({ resolver, defaultValues: data.formData, resetOptions: { keepValues: true } })
useEffect(() => {
if (isSubmitSuccessful) {
reset()
}
}, [isSubmitSuccessful, reset]) But that does not work for me with remix-hook-form, This was the only way I could get the behaviour I want, using const {
register,
handleSubmit,
reset,
getValues,
formState: { errors, isDirty, isSubmitSuccessful },
} = useRemixForm<Inputs>({ resolver, defaultValues: data.formData })
useEffect(() => {
if (isSubmitSuccessful) {
reset(getValues())
}
}, [isSubmitSuccessful, reset, getValues]) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Added a sandbox here: https://codesandbox.io/p/devbox/silly-jepsen-gzp9mr |
Beta Was this translation helpful? Give feedback.
0 replies
-
this should be an issue? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am having some trouble understanding how to deal with a dirty form after submission.
In a route I have:
(Tthere are no redirects or route changes.)
BUT, the form still reports isDirty = true.
If I invoke reset on the form in response to a change in the isSubmitSuccessful form state, the inputs reset to the previously unchanged values, which is not what I want.
If I add a useEffect with a dependency on the default values, it DOES reset the form and the dirty status, but there is a momentary flash of it changing first to the old values, which is not nice from a UX perspective, and this seemed like a hack tbh.
I suppose I expected that the new default values would trigger the form to reset, since in principle the form values now match the values in the inputs. It seems like the form inputs are somehow not quite in sync with the new default values, even though they appear to be the same.
Anyone has any suggestions or a pointer to a similar example?
This is similar to, but not the same as, #60 and #62.
Beta Was this translation helpful? Give feedback.
All reactions