airjp73 / rvf

Easy form validation and state management for React and Remix
https://rvf-js.io
MIT License
826 stars 66 forks source link

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

Closed haines closed 7 months ago

haines commented 7 months ago

Which packages are impacted?

What version of these packages are you using?

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 commented 7 months ago

This may be caused by https://github.com/colinhacks/zod/issues/3123?

haines commented 7 months ago

Confirmed, this is a bug upstream and is resolved by https://github.com/colinhacks/zod/pull/3124.