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.

Max length validation

Ian MacCallum28ea7e690e11
diff --git a/apps/web/ui/partners/groups/design/fields/long-text-field.tsx b/apps/web/ui/partners/groups/design/fields/long-text-field.tsx
index 7bc5352cc8..99c3f26437 100644
--- a/apps/web/ui/partners/groups/design/fields/long-text-field.tsx
+++ b/apps/web/ui/partners/groups/design/fields/long-text-field.tsx
@@ -5,7 +5,6 @@ import { z } from "zod";
import { FormControl } from "./form-control";
import { MaxCharacterCount } from "./max-character-count";
-
export function LongTextField({
keyPath: keyPathProp,
field,
@@ -20,29 +19,33 @@ export function LongTextField({
const value = watch(keyPath);
const state = getFieldState(keyPath);
const currentLength = value?.length || 0;
- const exceedsMaxLength = field.data.maxLength && currentLength > field.data.maxLength;
+ const exceedsMaxLength =
+ field.data.maxLength && currentLength > field.data.maxLength;
const error = !!state.error || exceedsMaxLength;
return (
- <FormControl
- label={field.label}
- required={field.required}
- >
+ <FormControl label={field.label} required={field.required}>
<textarea
className={cn(
- "mt-2 block w-full rounded-md focus:outline-none text-sm",
+ "mt-2 block w-full rounded-md text-sm focus:outline-none",
error
? "border-red-400 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
: "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-[var(--brand)] focus:ring-[var(--brand)]",
)}
placeholder={field.data.placeholder || ""}
- {...(preview ? {} : register(keyPath, {
- required: field.required,
- }))}
+ {...(preview
+ ? {}
+ : register(keyPath, {
+ required: field.required,
+ maxLength: field.data.maxLength,
+ }))}
/>
{field.data.maxLength && (
- <MaxCharacterCount currentLength={currentLength} maxLength={field.data.maxLength} />
+ <MaxCharacterCount
+ currentLength={currentLength}
+ maxLength={field.data.maxLength}
+ />
)}
</FormControl>
);
diff --git a/apps/web/ui/partners/groups/design/fields/short-text-field.tsx b/apps/web/ui/partners/groups/design/fields/short-text-field.tsx
index 74f682eb6c..8376e550e8 100644
--- a/apps/web/ui/partners/groups/design/fields/short-text-field.tsx
+++ b/apps/web/ui/partners/groups/design/fields/short-text-field.tsx
@@ -2,10 +2,12 @@ import { programApplicationFormShortTextFieldSchema } from "@/lib/zod/schemas/pr
import { cn } from "@dub/utils";
import { useFormContext } from "react-hook-form";
import { z } from "zod";
-import { MaxCharacterCount } from "./max-character-count";
import { FormControl } from "./form-control";
+import { MaxCharacterCount } from "./max-character-count";
-type ShortTextFieldData = z.infer<typeof programApplicationFormShortTextFieldSchema>
+type ShortTextFieldData = z.infer<
+ typeof programApplicationFormShortTextFieldSchema
+>;
export function ShortTextField({
keyPath: keyPathProp,
@@ -21,30 +23,34 @@ export function ShortTextField({
const value = watch(keyPath);
const state = getFieldState(keyPath);
const currentLength = value?.length || 0;
- const exceedsMaxLength = field.data.maxLength && currentLength > field.data.maxLength;
+ const exceedsMaxLength =
+ field.data.maxLength && currentLength > field.data.maxLength;
const error = !!state.error || exceedsMaxLength;
return (
- <FormControl
- label={field.label}
- required={field.required}
- >
+ <FormControl label={field.label} required={field.required}>
<input
className={cn(
- "mt-2 block w-full rounded-md focus:outline-none text-sm",
+ "mt-2 block w-full rounded-md text-sm focus:outline-none",
error
? "border-red-400 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
: "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-[var(--brand)] focus:ring-[var(--brand)]",
)}
placeholder={field.data.placeholder || ""}
- {...(preview ? {} : register(keyPath, {
- required: field.required,
- }))}
+ {...(preview
+ ? {}
+ : register(keyPath, {
+ required: field.required,
+ maxLength: field.data.maxLength,
+ }))}
/>
{field.data.maxLength && (
- <MaxCharacterCount currentLength={currentLength} maxLength={field.data.maxLength} />
+ <MaxCharacterCount
+ currentLength={currentLength}
+ maxLength={field.data.maxLength}
+ />
)}
- </FormControl >
+ </FormControl>
);
}