A one-time code made of single-character boxes.
<.otp_input field={@form[:code]} label="Codigo de 6 digitos" />
<.otp_input name="pin" length={4} mask autofocus />
<.otp_input field={@form[:code]} separator={3} on_complete="verify" />
<.otp_input name="invite" mode="alphanumeric" length={8} size="lg" />Typing fills a box and moves to the next, Backspace on an empty box goes back and empties the
previous one, the arrows, Home and End move between boxes, and a paste or an autofill spreads
its characters over the boxes. Characters the mode does not allow are dropped.
The boxes have no name: a hidden input named like the field carries the joined code and fires
a bubbling input event whenever it changes, so a surrounding phx-change receives
%{"name" => "482913"} (a partial code while it is typed). A value the server sends later
wins over the one in the browser (render value="" to clear a rejected code).
on_complete is an event name or a %JS{}; it is sent to target (or the LiveView) each time
the code changes while every box is filled, with %{"id" => id, "name" => name, "value" => code}.
The behaviour lives in the LedgerUI.Otp hook (file otp.js), so the component needs a stable
id (from field or name).
With autofocus the box that takes the focus first (the first empty one) is rendered with the
on class, so the caret shows before the hook runs.
Summary
Functions
Renders the boxes, with their caption, help and errors when given.
Functions
Renders the boxes, with their caption, help and errors when given.
Attributes
id(:string) - Defaults tonil.name(:string) - Defaults tonil.value(:any) - Defaults tonil.field(Phoenix.HTML.FormField) - Defaults tonil.label(:string) - Defaults tonil.label_class(:any) - Defaults tonil.help(:string) - Defaults tonil.errors(:list) - Defaults to[].state(:string) - Defaults tonil.Must be one ofnil,"","success", or"error".length(:integer) - Defaults to6.mode(:string) - Defaults to"numeric". Must be one of"numeric", or"alphanumeric".size(:string) - Defaults tonil.Must be one ofnil,"sm","md", or"lg".mask(:boolean) - Defaults tofalse.disabled(:boolean) - Defaults tofalse.autofocus(:boolean) - Defaults tofalse.separator(:any) - Defaults tonil.on_complete(:any) - Defaults tonil.target(:any) - Defaults tonil.aria_label(:string) - Defaults to"One-time code".digit_label(:string) - Defaults to"Digit".wrapper_class(:any) - Defaults tonil.class(:any) - Defaults tonil.- Global attributes are accepted.