Unique Text Field
UniqueTextField is a specialized reusable input component for Shaddy Form responsible for collecting unique user input.
⚠️ This content is not available in your language yet.
UniqueTextField
is a specialized input component for Shaddy Form that checks if the entered value is unique (e.g., for usernames or emails). It provides instant feedback with a loading spinner and success/error indicators, using a debounced async check function.
Installation
pnpm dlx shadcn@latest add https://shaddy-docs.vercel.app/r/unique-text-field
Props
Name | Type | Default | Description |
---|---|---|---|
name | string (from react-hook-form Path) | required | The field name (must match your form schema). |
label | string | The label displayed above the input. | |
placeholder | string | Placeholder text for the input. | |
required | boolean | false | Marks the field as required. |
className | string | Additional CSS classes for the field container. | |
type | 'text' | 'email' | 'text' | The input type. |
checkFunction | (value: string) => Promise<boolean> | required | Async function to check if the value is unique. Should return true if available. |
debounceMs | number | 1000 | Debounce time in milliseconds before checking uniqueness. |
Usage
async function checkUsernameUnique(username: string) {
// Replace with your API call
return !["taken", "admin"].includes(username);
}
<ShaddyForm>
<UniqueTextField
name="username"
label="Username"
required
placeholder="Enter a unique username"
checkFunction={checkUsernameUnique}
debounceMs={800}
/>
</ShaddyForm>;
Notes
- The
checkFunction
should return a Promise that resolves totrue
if the value is available/unique, orfalse
if taken.