A numeric field for money and quantities that shows the number the way the person's locale
writes it (1.234,56 in pt-BR, 1,234.56 in en) and submits the plain machine value
(1234.56).
<.number_input field={@form[:price]} label="Price" prefix="R$" decimals={2} min={0} />
<.number_input field={@form[:quantity]} label="Quantity" steppers min={1} step={1} suffix="un" />
<.number_input name="qty" value={3} steppers stepper_style="round" min={0} />The control is the design's lu-num: the number is a span.v that the LedgerUI.NumberInput
hook (priv/static/ledger_ui/hooks/number_input.js) makes editable (contenteditable,
role="spinbutton"); a hidden input named like the field carries the machine value and fires a
bubbling input event when it changes, so a surrounding phx-change runs. Typing keeps what
the person writes; leaving the field clamps to min/max, rounds to decimals/max_decimals
and writes it grouped. Arrow up/down (and the steppers) move by step, Page up/down by ten
steps. The steppers are disabled at min and max by the hook.
Deviations from the README: align defaults to "center" (the design's value), and the
accessible names of the steppers default to the locale's (Diminuir/Aumentar in pt-BR).
Summary
Functions
Formats a number for display, as the field shows it.
Renders the number input.
Same as number_input/1 (same attributes and slots), under the name the design vitrine uses.
Functions
Formats a number for display, as the field shows it.
iex> LedgerUI.Components.NumberInput.format_number(1284.9, decimals: 2)
"1.284,90"
iex> LedgerUI.Components.NumberInput.format_number(12.5, locale: "en", max_decimals: 2)
"12.5"
Renders the number input.
Attributes
id(:string) - Defaults tonil.name(:string) - Defaults tonil.value(:any)field(Phoenix.HTML.FormField) - Defaults tonil.label(:string) - Defaults tonil.label_class(:any) - Defaults tonil.help(:string) - Defaults tonil.errors(:list) - Defaults to[].disabled(:boolean) - Defaults tofalse.locale(:string) - Defaults to"pt-BR". Must be one of"pt-BR","pt_BR", or"en".decimal_separator(:string) - Defaults tonil.thousands_separator(:string) - Defaults tonil.decimals(:integer) - Defaults tonil.max_decimals(:integer) - Defaults tonil.min(:any) - Defaults tonil.max(:any) - Defaults tonil.step(:any) - Defaults to1.steppers(:boolean) - Defaults tofalse.stepper_style(:string) - Defaults to"inset". Must be one of"inset","round", or"joined".decrement_label(:string) - Defaults tonil.increment_label(:string) - Defaults tonil.prefix(:string) - Defaults tonil.suffix(:string) - Defaults tonil.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".align(:string) - Defaults to"center". Must be one of"left","right", or"center".wrapper_class(:any) - Defaults tonil.canvas(:boolean) - The block of the canvas app templates: adiv.lu-numwhose minus button is.minus(otherwise aspan). Defaults tofalse.class(:any) - Defaults tonil.- Global attributes are accepted.
Same as number_input/1 (same attributes and slots), under the name the design vitrine uses.
Attributes
id(:string) - Defaults tonil.name(:string) - Defaults tonil.value(:any)field(Phoenix.HTML.FormField) - Defaults tonil.label(:string) - Defaults tonil.label_class(:any) - Defaults tonil.help(:string) - Defaults tonil.errors(:list) - Defaults to[].disabled(:boolean) - Defaults tofalse.locale(:string) - Defaults to"pt-BR". Must be one of"pt-BR","pt_BR", or"en".decimal_separator(:string) - Defaults tonil.thousands_separator(:string) - Defaults tonil.decimals(:integer) - Defaults tonil.max_decimals(:integer) - Defaults tonil.min(:any) - Defaults tonil.max(:any) - Defaults tonil.step(:any) - Defaults to1.steppers(:boolean) - Defaults tofalse.stepper_style(:string) - Defaults to"inset". Must be one of"inset","round", or"joined".decrement_label(:string) - Defaults tonil.increment_label(:string) - Defaults tonil.prefix(:string) - Defaults tonil.suffix(:string) - Defaults tonil.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".align(:string) - Defaults to"center". Must be one of"left","right", or"center".wrapper_class(:any) - Defaults tonil.canvas(:boolean) - The block of the canvas app templates: adiv.lu-numwhose minus button is.minus(otherwise aspan). Defaults tofalse.class(:any) - Defaults tonil.- Global attributes are accepted.