Digit input
Collects a short code one character per box, such as a one-time verification code.
Types
numeric
is the default.
alphanumeric
and
alphabetic
accept letters.
<.digit_input id="digit-input-numeric" characters={6} placeholder="•" />
<.digit_input id="digit-input-alphanumeric" type="alphanumeric" characters={6} placeholder="•" />
<.digit_input id="digit-input-alphabetic" type="alphabetic" characters={4} placeholder="•" />
One-time code
With
otp
, browsers can fill in a code received by email or text message.
<.digit_input
id="digit-input-otp"
characters={6}
otp
placeholder="•"
on_complete="verify_code"
/>
Lengths
characters
sets the number of boxes.
<.digit_input id="digit-input-length-4" characters={4} placeholder="•" />
<.digit_input id="digit-input-length-8" characters={8} placeholder="•" />
Error
<.digit_input id="digit-input-error" characters={6} placeholder="•" error />
Disabled
<.digit_input id="digit-input-disabled" characters={6} placeholder="•" disabled />
Guidelines
-
Set
otpfor one-time codes so browsers and password managers can fill the code in. -
Match
typeto the characters the code can contain. Characters of another type are rejected. -
The digit input doesn't submit with a form. Read the code from the
on_completeevent, which receivesvalueas a list andvalueAsStringas one string. -
Set
errorwhen the code is wrong, and explain what to do next in the text around the input. -
Focus leaves the input once every box is filled, so handle
on_completeinstead of waiting for a submit.
API reference
<.digit_input>
| Attribute | Type | Default | Description |
|---|---|---|---|
|
characters
Required
|
integer
|
–
|
The number of characters in the input
|
|
disabled
|
boolean
|
false
|
|
|
error
|
boolean
|
false
|
|
|
id
Required
|
string
|
–
|
|
|
on_change
|
string
|
nil
|
Event handler for when the input changes. Triggers the event with value
{ value: string[],
valueAsString: string }
|
|
on_complete
|
string
|
nil
|
Event handler for when the input is complete. Triggers the event with value
{ value: string[],
valueAsString: string }
|
|
on_invalid
|
string
|
nil
|
Event handler for when the input is invalid. Triggers the event with value
{ value: string[],
valueAsString: string }
|
|
otp
|
boolean
|
false
|
|
|
placeholder
|
string
|
nil
|
|
|
type
|
string
|
"numeric"
|
"alphanumeric""numeric""alphabetic"
|
Also accepts global attributes.