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

Undefined value using select with react hook form #124

Closed
t-rosa opened this issue Mar 14, 2023 · 3 comments
Closed

Undefined value using select with react hook form #124

t-rosa opened this issue Mar 14, 2023 · 3 comments

Comments

@t-rosa
Copy link

t-rosa commented Mar 14, 2023

Hello!

I don't know why my form submission doesn't pass the validation check using react hook form and radix select primitive.
After selecting a value, this one still undefined and the resolvers do it's job telling me the field is required.

The form :
image

useForm:
image

image

Any idea ?

@emicba
Copy link
Contributor

emicba commented Mar 14, 2023

You might need to use the Controller component from react-hook-form: https://react-hook-form.com/get-started/#IntegratingwithUIlibraries.

When spreading the register('field') you are passing onChange but the Select.Root is expecting onValueChange.

Here is a working example https://codesandbox.io/s/shadcn-ui-select-react-hook-form-mgmdmv

@t-rosa
Copy link
Author

t-rosa commented Mar 14, 2023

It works, thanks!

@t-rosa t-rosa closed this as completed Mar 14, 2023
@feliche93
Copy link

@emicba thanks for sharing, ran into the same issue 🙏

This issue was closed.
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

3 participants