react hook form + headless ui

from @dingo "Ok so I have a drop-down where you can select something, I want to show the names of the options but the “value” be the database id for them. I think it should be done this way as far as I can tell because I’m just accepting the database id as a string in my zod schema (I use the same schema for my backend route for said action)" I made it a bit fancy with a generic combobox, so hopefully this helps https://codesandbox.io/p/sandbox/goofy-scooby-mg9qm7
goofy-scooby-mg9qm7
CodeSandbox is an online editor tailored for web applications.
10 Replies
awexis
awexisOP2y ago
Shows the Names on the combobox, but once you submit, you can see in the console log that it's the id of the name :>
dingo
dingo2y ago
This looks to be what I want to do, I just wanted to have a value function that chose the value for the output via the passed in generic single item, not sure if that's what you thought I meant, I might have to further abstract my approach to do it like your example I'm going to try to reimplement my solution later. Thanks for the help 🙂
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
dingo
dingo2y ago
The problem is that my form is validated with my zod schema, if it isnt a string that is an id then it fails, I can't grab it from the submit handler because the submit handler only gets called when the schema has been validated correctly against the form...
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
dingo
dingo2y ago
I suppose but that means that if I use that api query anywhere else im going to have to do a nested object
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
dingo
dingo2y ago
@awexis Do you prefer combobox (single mode) over select?
awexis
awexisOP2y ago
Wym? Its up to you really 🙂
dingo
dingo2y ago
Hm @Valhalaar
Want results from more Discord servers?
Add your server