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

The Forms in the official example of the Select component pass validation even if they are not selected #7421

Open
1 of 4 tasks
ducle-c opened this issue Mar 12, 2025 · 1 comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible

Comments

@ducle-c
Copy link

ducle-c commented Mar 12, 2025

Describe the bug

{{ $form.city.error.message }}
<script setup> import { ref } from 'vue'; import { zodResolver } from '@primevue/forms/resolvers/zod'; import { useToast } from "primevue/usetoast"; import { z } from 'zod'; const toast = useToast(); const initialValues = ref({ city: { name: '' } }); const resolver = ref(zodResolver( z.object({ city: z.union([ z.object({ name: z.string().min(1, 'City is required.') }), z.any().refine((val) => false, { message: 'City is required.' }) ]) }) )); const cities = ref([ { name: 'New York', code: 'NY' }, { name: 'Rome', code: 'RM' }, { name: 'London', code: 'LDN' }, { name: 'Istanbul', code: 'IST' }, { name: 'Paris', code: 'PRS' } ]); const onFormSubmit = ({ valid }) => { if (valid) { toast.add({ severity: 'success', summary: 'Form is submitted.', life: 3000 }); } }; </script>

This is the content of the official example, in the case of no select can still pass the verification, after testing found that FormSubmitEvent valid is true, but values is undefined, why undefined can pass the verification?

Pull Request Link

No response

Reason for not contributing a PR

  • Lack of time
  • Unsure how to implement the fix/feature
  • Difficulty understanding the codebase
  • Other

Other Reason

No response

Reproducer

https://stackblitz.com/edit/primevue-4-vite-issue-template-1ttjhorl?file=src%2FApp.vue

Environment

"primevue": "^4.3.1",
"@primevue/forms": "^4.3.1",
"vue": "^3.5.13",
"zod": "^3.24.2"

Vue version

4.3.1

PrimeVue version

4.3.1

Node version

No response

Browser(s)

No response

Steps to reproduce the behavior

It passes validation if select is not selected

Expected behavior

Ability to verify the null value of select

@ducle-c ducle-c added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Mar 12, 2025
@wangziling
Copy link
Contributor

I thought maybe this is not the issue of primevue.

It seems you'd better to use the simpler solution:

Point out the optionValue prop on the <Select /> component.
Image

The make sure the city value is string format.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible
Projects
None yet
Development

No branches or pull requests

2 participants