auto-form icon indicating copy to clipboard operation
auto-form copied to clipboard

[SELECT] Can't find a way to get select values

Open LiteBluSky opened this issue 6 months ago • 2 comments

I hit a dead end again with the select component...

I want to display labels and validate values! As I've read in the docs, zod validates the labels, is there a workaround for this usecase?

country: z
      .nativeEnum(
        regions.reduce(
          (acc, region) => {
            acc[region.code] = region.displayName;
            return acc;
          },
          {} as Record<string, string>,
        ),
      )

LiteBluSky avatar Jul 02 '25 10:07 LiteBluSky


const hi = {
  "label 1": "value1",
  "label 2": "value2",
  "label 3": "value3",
} as const;

<SelectContent>
        {(field.options || []).map(([key, label]) => (
          <SelectItem key={key} value={label}>
            {key}
          </SelectItem>
        ))}
</SelectContent>

try this

adityacodepublic avatar Jul 02 '25 12:07 adityacodepublic

I never even thought about that...

<SelectContent>
        {(field.options || []).map(([key, label]) => (
          <SelectItem key={key} value={label}> // changed the value to the label
            {key} // changed from label to key 
          </SelectItem>
        ))}
</SelectContent>

LiteBluSky avatar Jul 02 '25 13:07 LiteBluSky