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

Validating with Zod not applying the .transform() method after 4.12.0 update #4565

Closed
5 tasks done
RazorSiM opened this issue Nov 28, 2023 · 4 comments
Closed
5 tasks done

Comments

@RazorSiM
Copy link

What happened?

I'm using the .transform() method to edit the data to be sent to the form submit function.
After the update to 4.12.0, the transform is not applied anymore to the values I get back from handleSubmit.

Note that type infers works: the api handler function is typed on the output of the schema and by passing the values from handleSubmit gives me no errors.

I can confirm it works with the 4.11.8 release.

Repdoduction:
https://stackblitz.com/edit/vue3-script-setup-with-vite-ujk93v?file=src%2FApp.vue

v4.12.1:
The values are parsed by the schema validator, but the original ones are passed to the handleSubmit.
image

v4.11.8:
Try to set the vee-validate and @vee-validate/zod packages to 4.11.8 and run the example again, you will see the transformed data is passed through the handleSubmit now.
image

Reproduction steps

  1. Create a zod schema with a transform
  2. Validate a form, log the values from handleSubmit
  3. The values are not transformed

Version

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

What browsers are you seeing the problem on?

  • Firefox
  • Chrome
  • Safari
  • Microsoft Edge

Relevant log output

No response

Demo link

https://stackblitz.com/edit/vue3-script-setup-with-vite-ujk93v?file=src%2FApp.vue

Code of Conduct

@logaretm
Copy link
Owner

Thanks for reporting this, should be fixed with the next release.

@jbogheand
Copy link

jbogheand commented Mar 18, 2024

Has this been fixed? @logaretm

In my case neither the .toUpperCase() or .transform((val) => val.toUpperCase()) seem to work:

accountNumber: toTypedSchema(
    zod.coerce
      .string()
      .trim()
      .toUpperCase()
      .regex(/^[A-Z0-9]*$/, "can only have letters and numbers!")
      .min(6, "must be 6 characters long!")
      .max(6, "must be 6 characters long!")
      .transform((val) => val.toUpperCase())
  ),

Provided value
image

Logged inside handleSubmit
image

Expected
A12345

@jbogheand
Copy link

jbogheand commented Mar 22, 2024

I ran some more tests and figured out this works for defineField but does not work for useField.
I believe this pull request is trying to fix that #4692

@mehcode
Copy link

mehcode commented Mar 25, 2024

Yeah. That PR works for our cases right now.

I haven't tried every scenario but I've been adapting our product to use vee-validate and really like it overall, but I much prefer the patten of scoping rules within specific components such as a UsernameField or a PhoneNumberField for example and having that bubble and transform up to the containing form.

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

4 participants