Set error when onSubmit fails
Im desperately trying to make server validation work. I've tried to use formApi.fieldInfo.email.instance?.setErrorMap and formApi.setErrorMap inside onSubmit, but nothing seems to work.
How to consistenly set an error the onsubmit fails?
6 Replies
quickest-silver•4w ago
until
createErroris added in, the easiest way is to have your endpoint call in validators.onSubmitAsync.
If the endpoint succeeded, return nothing.
If the endpoint threw validation errors, return those errors.
Don't blame the user for random server errors. They can't submit with errors present.national-goldOP•4w ago
Thanks.. The use case here is not to handle random server errors, it's to present actual errors correctly to the user. The current use case i have is to validate the uniqueness of an email address. I haven't looked into the async validators that much (the documentation is a bit lacking sadly)
cloudy-cyan•4w ago
By providing an Endpoint that tells anonymous users if an entered E-Mail-Address is unique you're possibly giving away the information if a user with this address is registered on your app/site/service which could be missused.
There's some WIP docs regarding error handling here: https://github.com/TanStack/form/pull/1566/files
national-goldOP•4w ago
I'm using react server actions, so this should not be an issue...
cloudy-cyan•4w ago
Let's say you are running some-shady-site.tld and I want to know if my colleague is registered there (I know their e-mail).
I go go your site, enter their mail and your endpoint will respond with
this e-mail is not unique
Then I know that colleague is registered with your site, right?national-goldOP•4w ago
Your question is not really relevant for my problem here. I know about the consequences you're talking about, its just a separate issue and not really relevant to the tanstack form question.