Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting server errors #27

Open
tjaska opened this issue Jun 19, 2024 · 0 comments
Open

Setting server errors #27

tjaska opened this issue Jun 19, 2024 · 0 comments

Comments

@tjaska
Copy link

tjaska commented Jun 19, 2024

Is there a way to set errors manually, specifically for when we get them after submitting form?

Usecase:

  1. form validation passes
  2. mutation runs, server responds with Conflict, e.g. username is already in use
  3. show the error under username field

If not currently possible, would it be possible to implement (how complicated?).
What I have in mind is something like this

type ServerError = { field: string; errorMessage: string };

const serverErrors: ServerError[] = [
  {
    field: "username",
    errorMessage: "This username is already in use. Please choose another",
  },
];

<ZodForm 
// if undefined or empty, ignore
serverErrors={serverErrors}
...
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant