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

[Bug]: Only the first error is reported in an object with multiple zfd.text fields #349

Closed
1 of 4 tasks
haines opened this issue Jan 24, 2024 · 2 comments
Closed
1 of 4 tasks
Labels
bug Something isn't working

Comments

@haines
Copy link
Contributor

haines commented Jan 24, 2024

Which packages are impacted?

  • remix-validated-form
  • @remix-validated-form/with-zod
  • @remix-validated-form/with-yup
  • zod-form-data

What version of these packages are you using?

  • zod-form-data: 2.0.2
  • zod: 3.22.4

Please provide a link to a minimal reproduction of the issue.

https://codesandbox.io/p/sandbox/zod-form-data-text-bug-repro-swh7j3?file=%2Fsrc%2Findex.ts

Steps to Reproduce the Bug or Issue

  1. Use the zfd.text() helper for multiple fields in a z.object
  2. Validate an object where all the fields are set to empty string or omitted
  3. Get a "Required" error on the first field

Expected behavior

Get a "Required" error on all the fields

Screenshots or Videos

No response

Platform

N/A

Additional context

I would expect these two schemas to be equivalent:

const zSchema = z.object({
  foo: z.string().min(1, "Required"),
  bar: z.string().min(1, "Required"),
  baz: z.string().min(1, "Required"),
});

const zfdSchema = z.object({
  foo: zfd.text(),
  bar: zfd.text(),
  baz: zfd.text(),
});

However, when validating the data { "foo": "", "bar": "" }, the former correctly produces errors on all three fields. The latter only produces an error for the first field.

@haines haines added the bug Something isn't working label Jan 24, 2024
@haines
Copy link
Contributor Author

haines commented Jan 24, 2024

This may be caused by colinhacks/zod#3123?

@haines
Copy link
Contributor Author

haines commented Jan 24, 2024

Confirmed, this is a bug upstream and is resolved by colinhacks/zod#3124.

@haines haines closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant