Skip to content

issue: Zod resolver does not respect union error #808

@IanVS

Description

@IanVS

Version Number

5.2.1

Codesandbox/Expo snack

https://stackblitz.com/edit/vitejs-vite-cntkt5yv?file=README.md

Steps to reproduce

  1. Read the readme of the stackblitz
  2. Focus the input in the preview and press enter
  3. The error is shown as "Invalid host or port"

Expected behaviour

My schema is a union, which has an error handler in order to decide what to show based on the errors of the constituent schemas. I expected the error message returned by my union to be used in the form, but instead the first error from the first schema in the union is used instead, due to this line:

const unionError = error.errors[0][0];

Now that error handlers are only per-schema (see colinhacks/zod#4893 (comment)), I'm not sure how else to accomplish what I'm trying to do, which is to validate a single input field which can accept either an IPv4 address with a port, an IPv6 address with a port, or an empty string.

What browsers are you seeing the problem on?

No response

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions