Can I set errors of specific field when onSubmit failed? #1106
-
Let's say, in Login, Then I want to display this message as a field error. then how could I do that? I tried this, and this works. const form = useForm({
onSubmit: async ({ value, formApi }) => {
try {
await submit(value)
} catch (e) {
// using setFieldMeta
formApi.setFieldMeta("password", {
...formApi.getFieldMeta("password")!,
errorMap: { onSubmit: "Unknown Error Occurred" },
})
// or this
formApi.fieldInfo.password.instance?.setErrorMap({ onSubmit: "Unknown Error Occurred" });
}
}
}) |
Beta Was this translation helpful? Give feedback.
Answered by
FourwingsY
Jan 13, 2025
Replies: 2 comments 2 replies
-
You can return an object from the form return {
fields: {
password: "Unknown Error Occurred"
},
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
This is same discussion of #623 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summarizing answer from the thread
tldr; "SUBMIT IN A VALIDATOR", if your call returns validation results.
Submit flow of tanstack/form
So If my server is running validation on request, (even if it commits transaction)
validators.onSubmitAsync