The boxes of a one-time code, one character each: the code sent by SMS or e-mail, a two-factor code. Typing a
digit fills its box and moves on; pasting the code fills every box; Backspace clears a box and, on an empty one,
steps back; the arrows, Home and End move between boxes (DevactionUI.OtpInput hook, logic in text.js).
The boxes have no name: the code goes, joined, into one hidden input (name), which fires input (and
change when every box is full) so a form with phx-change hears it. Every box has autocomplete="one-time-code"
and a numeric keyboard (inputmode="numeric"), so the phone offers the code it just got, which arrives as one value
and is spread over the boxes. numeric false takes letters and digits.
The state is status: :idle (an empty box has a quiet border, a filled one a stronger one, the focused one the
ink), :error (red boxes, aria-invalid, and the helper is announced as an alert) or :ok (green boxes). The
line under the boxes is the helper attr (2 digits to go), and the line under that, such as Did not arrive? Resend in 0:24, is the resend slot, so the caller draws the countdown and the button. Words are all attrs and
slots: label names the group and box_label names each box (Digit %{n} of %{total}).
Summary
Functions
Attributes
id(:string) (required)name(:string) (required) - the name of the hidden input that carries the joined code.label(:string) (required) - names the group of boxes, e.g.Verification code.box_label(:string) (required) - names each box;%{n}and%{total}are filled in, as inDigit %{n} of %{total}.value(:string) - the code so far, as the server knows it. Defaults to"".length(:integer) - how many boxes. Defaults to6.separator_after(:integer) - puts a separator after this many boxes, e.g.3for482 – 913. Defaults tonil.status(:atom) - Defaults to:idle. Must be one of:idle,:error, or:ok.numeric(:boolean) - digits only, with a numeric keyboard; false takes letters too. Defaults totrue.disabled(:boolean) - Defaults tofalse.autofocus(:boolean) - focuses the first box on load. Defaults tofalse.helper(:string) - the line under the boxes, such as2 digits to goorWrong code. 2 tries left.. Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.
Slots
separator- between the boxes atseparator_after; a short dash when empty.resend- the line under the helper, such asDid not arrive? <button>Resend in 0:24</button>.