Browse docs
Browse docs
One-time password field that renders individual character boxes. Supports numeric, alphanumeric, and alphabetic input modes. Integrates with DashForm automatically.
import { DashForm } from '@dashforge/forms';
import { OTPField } from '@dashforge/ui';
function VerifyForm() {
return (
<DashForm onSubmit={(data) => console.log(data)}>
<OTPField
name="otp"
label="Verification Code"
length={6}
onComplete={(value) => console.log('Code entered:', value)}
rules={{ required: 'Code is required' }}
/>
</DashForm>
);
}Six numeric slots bound to the form by name. The form stores a single
concatenated string (e.g. "123456"); paste a full code into the first
slot and it distributes across all slots.
<OTPField name="code" label="Verification code" length={6} />mode="alphanumeric" accepts letters and digits. The default is
"numeric"; "alpha" accepts letters only.
<OTPField name="code" label="Alphanumeric code" mode="alphanumeric" length={6} />length controls how many slots render — here a 4-digit PIN.
<OTPField name="pin" label="PIN" length={4} />Error state with helper text — in a real form this is driven by validation or a rejected server response.
Invalid code. Please try again.
<OTPField
name="code"
label="Verification code"
error
helperText="Invalid code. Please try again."
/>| Prop | Type | Default | Description |
|---|---|---|---|
name | string | — | Field name. Required. |
length | number | 6 | Number of OTP character boxes. |
mode | 'numeric' | 'alphanumeric' | 'alpha' | 'numeric' | Allowed character set. |
label | string | — | Field label displayed above the boxes. |
autoFocus | boolean | false | Focus the first box on mount. |
error | boolean | false | Error visual state. |
helperText | string | — | Hint or error text below the field. |
disabled | boolean | false | Disables all boxes. |
onComplete | (value: string) => void | — | Callback fired when all boxes are filled. |
rules | RegisterOptions | — | React Hook Form validation rules. |
onComplete for real-time verification flows (e.g. submitting as soon as the last digit is entered).OTPField supports progressive adoption — use it as a controlled component with an onComplete callback, integrate with React Hook Form, or conditionally show it based on other form state.
Available Now
Works as a standard React controlled component with value and onChange. No proprietary lock-in — use familiar patterns for OTP entry.
const [otp, setOtp] = useState('');
<OTPField
name="otp"
length={6}
value={otp}
onChange={setOtp}
onComplete={(value) => submitCode(value)}
/>Integration-Friendly
Integrates with React Hook Form via DashForm. Automatic validation, error handling, and touch tracking for OTP fields.
<DashForm>
<OTPField
name="otp"
length={6}
rules={{
required: 'Verification code is required',
minLength: {
value: 6,
message: 'Code must be 6 digits',
},
}}
/>
</DashForm>Available Now
Conditional rendering via visibleWhen. Show OTP field only when needed based on form state, like after phone number entry.
<OTPField
name="otp"
length={6}
visibleWhen={(engine) =>
engine.getNode('phoneNumber')?.value?.length === 10
}
/>