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

Select Component eum with custom data limitation #60

Open
nikolaischunk opened this issue Mar 3, 2024 · 0 comments
Open

Select Component eum with custom data limitation #60

nikolaischunk opened this issue Mar 3, 2024 · 0 comments

Comments

@nikolaischunk
Copy link

Thanks first of all for creating this awesome project!
While trying to integrate autoform into a project of mine, I came across a limitation of the select field.

The Problem

I have some data from a api that gets fetched on pageload with custom data.
It looks something like this:

const users = [{
id: '123',
name: 'hello'
},
{
id: '789,
name: 'world'
}]

I want to display the name of the field in the select menu, and when submitting it should pass the id.

label = name
value = id

In the docs I found this sentence:

// Keep in mind that zod will validate and return the enum labels, not the enum values!

I am not sure why this is, but this seems very unintuitive, especially when working with values that are not just simple 'one value' enums.

Solution?

Is there a way to work around this? Or even improve the Code to allow for the value to be validated not the label?
Or using a different (custom) datatype, an array of objects with label & value attributes for example

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

1 participant