shadcn.io is not affiliated with official shadcn/ui
Input OTP examples · Behavior
Auto-submit OTP Input OTP for React
A one-time code form that submits on its own once all six digits are entered.
Most people type the last digit and wait. This example submits as soon as the code is complete, with no button to press. It's a Field with a One-Time Password label, a description saying the form submits by itself, and a FieldError for a short code.
Preview
Installation
FAQ
How does the form submit by itself?
The field's completion callback calls the same submit function as the form.
onComplete fires when the code reaches maxLength.
What if the form is submitted with a short code?
The form's submit handler runs the same check as auto-submit, so a code shorter than six shows Your one-time password must be 6 characters. in FieldError instead of being sent.
How is the error shown?
invalid on Field follows the error, and FieldError shows the message under the description. The error clears on the next valid submit.
What happens after submitting?
The example shows the result in a status line under the form instead of calling an API. Replace that with your request, and show its error in FieldError when the code is rejected. Here it reads Code submitted: and the code.
Related
- OTP in Form with Validation Input OTPA one-time code form that checks the code
- OTP with Resend Flow Input OTPA one-time code field with a 60-second
- Controlled OTP Input Input OTPA controlled one-time code field that
- Required Field Validation FormA name and an email field marked with
- OTP with Paste Optimization Input OTPA one-time code field with a Paste Code
- Input with LabelA text input with a label above it