vee-validate icon indicating copy to clipboard operation
vee-validate copied to clipboard

Field meta.required setted to false when use zod transform

Open ludhriq opened this issue 5 months ago • 0 comments

What happened?

When i use transform on my zod schema, the property meta.required of any field is setted to false. The validation of the fields works normally, but i want to use this property to insert a hint on the label of the field to the user knows that's a required field.

I took the code in the documentation Form-Level Validation Composition API as a basis for the example, just adding the transform to the schema

const validationSchema = toTypedSchema(zod.object({
    email: zod.string()
      .min(1, { message: 'This is required' })
      .email({ message: 'Must be a valid email' }),
    password: zod.string()
      .min(1, { message: 'This is required' })
      .min(8, { message: 'Too short' }),
  }).transform((values) => {
      return values;
  })
);

Image

Note: This behavior works correctly using validation with yup, meta.required is true when using transform and the field is required

Reproduction steps

  1. Execute the code to see the meta.required setted as false
  2. Delete the transform method on the schema and meta.required will be true

Version

Vue.js 3.x and vee-validate 4.x

What browsers are you seeing the problem on?

  • [ ] Firefox
  • [x] Chrome
  • [ ] Safari
  • [ ] Microsoft Edge

Relevant log output


Demo link

https://stackblitz.com/edit/vitejs-vite-tdty9ujv

Code of Conduct

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

ludhriq avatar May 13 '25 22:05 ludhriq