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

No error even though (global) zod validation fails #660

Closed
some-user123 opened this issue Sep 11, 2023 · 7 comments
Closed

No error even though (global) zod validation fails #660

some-user123 opened this issue Sep 11, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@some-user123
Copy link

Version

@nuxt/ui: 2.8.1
nuxt: 3.7.1

Reproduction Link

https://stackblitz.com/edit/nuxt-ui-puvf36?file=app.vue

Steps to reproduce

  • Press the button and see in the console, that validation failed.
  • Enter different values in the two fields.

What is Expected?

  • An error should be displayed.

What is actually happening?

  • Nothing

I guess, the problem is that the validation is not of one specific field but of two fields. However, as the zod validation failes in every case an error should be displayed. E.g. below all fields, or configurable below which field.

@some-user123 some-user123 added the bug Something isn't working label Sep 11, 2023
Copy link
Contributor

There is no bug; you simply need to include the path. You can find detailed instructions in the Zod documentation: https://zod.dev/?id=customize-error-path.

const formSchema = z.object({
  password: z.string(),
  repeatPassword: z.string()
})
  .refine((v) => v.password === v.repeatPassword, {
    message: 'passwords not equal',
    path: ['repeatPassword'] // <- missing this 
  })

image.png

@some-user123
Copy link
Author

Thanks for your feedback. I understand your point. However, from my perspective, nuxt/ui should act consistently. I.e., either visualize an error situation to the end user OR submit the form (and ignore the error without path).

Copy link
Member

@romhml Any thoughts on this?

@romhml
Copy link
Collaborator

romhml commented Sep 28, 2023

We can display global errors directly below the Form, I'll look into it. (Related to #625).

Copy link
Member

Should we reopen this then?

@romhml
Copy link
Collaborator

romhml commented Sep 28, 2023

It might be better to open a feature request and link both issue.

@romhml
Copy link
Collaborator

romhml commented Sep 28, 2023

The PR should also be pretty simple, I'll submit something today

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

4 participants