Verification code
Shows a box per digit for a one-time code sent by SMS or e-mail.
zb:input-otp zubazar/ui-pro
This component is in Zubazar UI Pro; Zubazar UI Pro brings Zubazar UI with it. Installing Zubazar UI Pro →
Basic usage
BLADE
There are 6 boxes by default; typing a digit moves to the next box and a pasted code is spread over the boxes.
<zb:input-otp label="Code sent by SMS" />
| Prop | Values |
|---|---|
label | Label above the boxes |
Number of digits
BLADE
length sets the number of boxes and name the hidden field the code is sent in.
<zb:input-otp :length="4" name="pin" label="4-digit PIN" />
| Prop | Values |
|---|---|
length | 6 (default) |
name | wire:model name or code |
value | Initial code |
In a form and with Livewire
BLADE
In a classic form the code is sent in a hidden field; wire:model is two-way and a code from the server is spread over the boxes.
{{-- Classic form: the code is submitted as "code" --}}
<form method="POST" action="{{ route('verification.check') }}">
@csrf
<zb:input-otp label="Verification code" required />
<zb:button type="submit" class="mt-4 w-full">Verify</zb:button>
</form>
{{-- Livewire --}}
<zb:input-otp wire:model="code" label="Verification code" hint="The code is valid for 5 minutes." />
| Prop | Values |
|---|---|
wire:model | The joined code; two-way |
hint | Shown when there is no error |
Props
The values the component takes. What are props and slots?
| Prop | Type | Default | Description |
|---|---|---|---|
length | number | 6 | Number of boxes (digits) |
name | — | null | Name of the hidden field the code is submitted with; otherwise the wire:model name, or code if that is missing too |
label | — | null | Label above the boxes |
value | — | null | Initial code (without wire:model / x-model); non-digit characters are dropped |
hint | — | null | Help text below the boxes when there is no error; linked to each box with aria-describedby |
input-class | — | null | Classes of each box; class places the whole field |
wire:model / x-model | — | — | Two-way: a code coming from the server is spread across the boxes; stays on the outer container |
Developer notes
- The boxes accept digits only; Backspace in an empty box goes back to the previous one.
- The first box has
autocomplete="one-time-code", so phones can suggest the SMS code; screen readers read the boxes as "digit 1", "digit 2". - The hidden field takes part in the form's change tracking; the boxes themselves do not.
required,disabledandaria-describedbygo to every box,autofocusto the first, otheraria-*anddata-*to the box group; the binding,classandwire:keystay on the outer wrapper.- A validation error shows below the boxes; without one,
hintshows.