Skip to content

Commit

Permalink
Merge pull request #18 from SteakFisher/dropdown-response-modification
Browse files Browse the repository at this point in the history
dropdown now uses id instead of value
  • Loading branch information
SteakFisher authored Jun 11, 2024
2 parents b9e1966 + 4c84408 commit 17bad11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/components/form-display/DropdownComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export default function DropdownComponent({ item, id } : { id: string; item: For
</CardHeader>
<CardContent>
<Select onValueChange={(value) => {
formResponses[id] = { selected: value, type: "dropdown" }
props.items.map((item) => {
if (item.value === value) {
formResponses[id] = { selected: item.id, type: "dropdown" }
}
})
}}>
<SelectTrigger className="w-[180px]">
<SelectValue placeholder="Select Item" />
Expand Down
2 changes: 1 addition & 1 deletion src/functions/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function validateDropdownInput(item: FormItem, response: DropdownResponse, error
if (!response.selected && !item.props.required) return;

// Workaround for zod to work tsk tsk
const zodLiterals = item.props.items.map((option) => z.literal(option.value)) as unknown as readonly [ z.ZodLiteral<string>, z.ZodLiteral<string>, ...z.ZodLiteral<string>[] ]
const zodLiterals = item.props.items.map((option) => z.literal(option.id)) as unknown as readonly [ z.ZodLiteral<string>, z.ZodLiteral<string>, ...z.ZodLiteral<string>[] ]

let dropdownResponseValidate = z.object({
selected: z.union(zodLiterals, {
Expand Down

0 comments on commit 17bad11

Please sign in to comment.