A phone number field with a country picker: a button at the left with the ISO code and the
calling code (BR +55), and the number input. The number is written in the national format of
the country as it is typed ((11) 91234-5678); what the form submits is the E.164 number
(+5511912345678).
<.phone_input field={@form[:phone]} label="Telefone" />
<.phone_input name="phone" country="US" label="Phone number" />
<.phone_input field={@form[:phone]} country="PT" country_order={~w(PT BR)} />
<.phone_input field={@form[:phone]} countries={~w(BR PT AR UY)} clearable />
<.phone_input name="phone" value="+5511912345678" size="lg" variant="filled" />country is the country the field starts with ("BR" by default); a value in E.164 selects
its own country. The picker is a searchable list (by name in Portuguese or English, ISO code or
calling code); country_order lists the countries shown first, countries limits the list and
except removes some. ISO codes are shown instead of flag emoji unless flags is set.
A hidden input with the field's name carries the E.164 number (empty while there are no
digits) and fires a bubbling input event when it changes, so phx-change runs; the visible
input has no name. phx-debounce and phx-throttle go to the hidden input.
Formatting is not validation
The format only helps reading. Validate on the server with
LedgerUI.Components.PhoneInput.Format.e164/2:
case LedgerUI.Components.PhoneInput.Format.e164(params["phone"], "BR") do
{:ok, e164} -> e164
{:error, reason} -> reason
endThe behaviour lives in the LedgerUI.PhoneInput hook (phone_input.js), so the field needs a
stable id (from field or name).
Summary
Functions
Renders the phone input.
Functions
Renders the phone input.
Attributes
id(:string) - Defaults tonil.name(:string) - Defaults tonil.value(:any) - Defaults tonil.field(Phoenix.HTML.FormField) - Defaults tonil.country(:string) - Defaults to"BR".country_order(:list) - Defaults to[].countries(:list) - Defaults to[].except(:list) - Defaults to[].locale(:string) - Defaults to"pt-BR".flags(:boolean) - Defaults tofalse.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".disabled(:boolean) - Defaults tofalse.variant(:string) - Defaults to"outlined". Must be one of"outlined", or"filled".size(:string) - Defaults to"md". Must be one of"sm","md", or"lg".shape(:string) - Defaults to"rounded". Must be one of"rounded", or"pill".clearable(:boolean) - Defaults tofalse.clear_label(:string) - Defaults to"Clear".picker_label(:string) - Defaults to"Country".search_placeholder(:string) - Defaults to"Search…".no_results(:string) - Defaults to"No results found".on_country_change(:string) - Defaults tonil.target(:any) - Defaults tonil.wrapper_class(:any) - Defaults tonil.class(:any) - Defaults tonil.style(:string) - Inline style of the.lu-inputbox (e.g. a width). Defaults tonil.- Global attributes are accepted. Supports all globals plus:
["autocomplete", "autofocus", "form", "placeholder", "readonly", "required"].