Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add min and max limits to the number lead form field

Rafi3bf23be4505d
diff --git a/apps/web/lib/zod/schemas/submitted-lead-form.ts b/apps/web/lib/zod/schemas/submitted-lead-form.ts
index ce46b0f854..08cd5a6e25 100644
--- a/apps/web/lib/zod/schemas/submitted-lead-form.ts
+++ b/apps/web/lib/zod/schemas/submitted-lead-form.ts
@@ -71,6 +71,12 @@ export const multiSelectFieldSchema = fieldCommonSchema.extend({
// Number
export const numberFieldSchema = fieldCommonSchema.extend({
type: z.literal("number"),
+ constraints: z
+ .object({
+ min: z.number().optional(),
+ max: z.number().optional(),
+ })
+ .optional(),
});
// Phone Number
diff --git a/apps/web/ui/submitted-leads/form-fields/number-field.tsx b/apps/web/ui/submitted-leads/form-fields/number-field.tsx
index 1db6a79d26..6572e72b6c 100644
--- a/apps/web/ui/submitted-leads/form-fields/number-field.tsx
+++ b/apps/web/ui/submitted-leads/form-fields/number-field.tsx
@@ -17,6 +17,8 @@ export function NumberField({
const keyPath = keyPathProp || `formData.${field.key}`;
const state = getFieldState(keyPath);
const error = !!state.error;
+ const min = field.constraints?.min;
+ const max = field.constraints?.max;
return (
<FormControl
@@ -27,6 +29,8 @@ export function NumberField({
>
<input
type="number"
+ min={min}
+ max={max}
className={cn(
"mt-2 block w-full rounded-md text-sm focus:outline-none",
error
@@ -36,6 +40,12 @@ export function NumberField({
{...register(keyPath, {
required: field.required,
valueAsNumber: true,
+ ...(min !== undefined && {
+ min: { value: min, message: `Must be at least ${min}` },
+ }),
+ ...(max !== undefined && {
+ max: { value: max, message: `Must be at most ${max}` },
+ }),
})}
/>
</FormControl>