Form cannot be resubmitted after setting onSubmit.form error via setErrorMap unless a field value changes
#2021
-
|
Hi 👋 I’m running into an issue with handling temporary server errors in TanStack Form and wanted to sanity-check my approach. I have a login form using const form = useAppForm({
defaultValues,
onSubmit: async (ctx) => {
const result = await login.mutateAsync({
username: ctx.value.email,
password: ctx.value.password,
});
if (result.ok) {
props.onSuccess();
} else {
ctx.formApi.setErrorMap({
onSubmit: { form: result.error, fields: {} },
});
}
},
onSubmitInvalid: () => {
formRef.current && focusOnFirstInvalid(formRef.current);
},
});ProblemAfter
This makes it difficult to handle temporary server errors (e.g. network issue, 500, rate limit), where the user should be able to simply click “Submit” again without changing anything. Questions
I may be misunderstanding the intended semantics of Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
I had a similar issue, and the workaround I found for the moment at least is to set <form
onSubmit={(e) => {
e.preventDefault();
e.stopPropagation();
form.setErrorMap({
onSubmit: {
fields: {},
},
});
form.handleSubmit();
}}
> |
Beta Was this translation helpful? Give feedback.
-
|
We're working on this. Please let us know if this API doesn't work for your needs for any reason |
Beta Was this translation helpful? Give feedback.
#2188
We're working on this. Please let us know if this API doesn't work for your needs for any reason