form.reset(): Add easy way to re-validate fields and reset metadata on reset #2049
Replies: 1 comment
|
What
Your workaround is the right call. One subtlety: You can wrap this in a const handleReset = useCallback(async () => {
form.reset()
await form.validateAllFields('mount')
for (const field of Object.keys(form.state.fieldMeta)) {
form.setFieldMeta(field as never, (prev) => ({
...prev,
isTouched: false,
isBlurred: false,
}))
}
}, [form])The proposal is solid. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Initial Discord post: https://discord.com/channels/719702312431386674/1474015671841984614
Context / need
My main use-case: canSubmit returns to
falseafter form.reset()Details
In building a form with a reset button, I noticed that fields aren't re-validated and isTouched/isBlurred is not reset.
In my case, I wanted
resetto make the form like it had never been touched.The ultimate goal was to re-disable the submit button after reseting the form.
Arguably, the desire to re-validate and reset meta state when calling
form.reset()will vary based on requirements.Right now, all of this needs to be done manually.
Proposal
form.reset()form.reset()Just an idea
All reactions