The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Show radio buttons for single choice lead form fields
Rafi0ad0cbcfcac4
diff --git a/apps/web/ui/submitted-leads/form-fields/multi-select-field.tsx b/apps/web/ui/submitted-leads/form-fields/multi-select-field.tsxindex 2a58aad191..f66b653f40 100644--- a/apps/web/ui/submitted-leads/form-fields/multi-select-field.tsx+++ b/apps/web/ui/submitted-leads/form-fields/multi-select-field.tsx@@ -1,5 +1,5 @@import { multiSelectFieldSchema } from "@/lib/zod/schemas/submitted-lead-form";-import { Checkbox } from "@dub/ui";+import { Checkbox, RadioGroup, RadioGroupItem } from "@dub/ui";import { Controller, useFormContext } from "react-hook-form";import * as z from "zod/v4";import { FormControl } from "./form-control";@@ -17,6 +17,8 @@ export function MultiSelectField({const keyPath = keyPathProp || `formData.${field.key}`;const state = getFieldState(keyPath, formState);const options = field.options;+ // Older fields have no value and allow multiple selections+ const multiple = field.multiple ?? true;return (<FormControl@@ -30,53 +32,83 @@ export function MultiSelectField({name={keyPath}rules={{validate: (val: any) => {- if (field.required && (!Array.isArray(val) || !val.length)) {+ if (!field.required) {+ return true;+ }+ if (!multiple && !val) {+ return "Please select an option";+ }+ if (multiple && (!Array.isArray(val) || !val.length)) {return "Please select at least one option";}return true;},}}- render={({ field: formField }) => (- <div className="mt-2 space-y-2">- {options.map((option) => {- const isSelected = formField.value?.includes(option.value);-- return (+ render={({ field: formField }) =>+ !multiple ? (+ <RadioGroup+ value={formField.value ?? ""}+ onValueChange={formField.onChange}+ className="mt-2 gap-2"+ >+ {options.map((option) => (<labelkey={option.value}- className="flex w-full items-center gap-2.5 text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"+ className="flex w-full items-center gap-2.5 text-sm font-medium leading-none"dir="auto">- <Checkbox- checked={isSelected}- className="border-border-default size-4 rounded focus:border-[var(--brand)] focus:ring-[var(--brand)] focus-visible:border-[var(--brand)] focus-visible:ring-[var(--brand)] data-[state=checked]:bg-black data-[state=indeterminate]:bg-black"- onCheckedChange={(checked) => {- if (checked) {- formField.onChange([- ...(formField.value || []),- option.value,- ]);- } else {- if (- Array.isArray(formField.value) &&- formField.value.includes(option.value)- ) {- formField.onChange(- formField.value.filter((v) => v !== option.value),- );- }- }- }}+ <RadioGroupItem+ value={option.value}+ className="size-4 border-neutral-300 text-black focus-visible:ring-[var(--brand)] data-[state=checked]:border-black"/>-<span className="text-content-emphasis text-sm">{option.label}</span></label>- );- })}- </div>- )}+ ))}+ </RadioGroup>+ ) : (+ <div className="mt-2 space-y-2">+ {options.map((option) => {+ const isSelected = formField.value?.includes(option.value);++ return (+ <label+ key={option.value}+ className="flex w-full items-center gap-2.5 text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"+ dir="auto"+ >+ <Checkbox+ checked={isSelected}+ className="border-border-default size-4 rounded focus:border-[var(--brand)] focus:ring-[var(--brand)] focus-visible:border-[var(--brand)] focus-visible:ring-[var(--brand)] data-[state=checked]:bg-black data-[state=indeterminate]:bg-black"+ onCheckedChange={(checked) => {+ if (checked) {+ formField.onChange([+ ...(formField.value || []),+ option.value,+ ]);+ } else {+ if (+ Array.isArray(formField.value) &&+ formField.value.includes(option.value)+ ) {+ formField.onChange(+ formField.value.filter((v) => v !== option.value),+ );+ }+ }+ }}+ />++ <span className="text-content-emphasis text-sm">+ {option.label}+ </span>+ </label>+ );+ })}+ </div>+ )+ }/></FormControl>);