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="discount" value={Decimal.new("12.5")} suffix="%" max_decimals={2} max={100} />
<.number_input field={@form[:amount]} locale="en" align="right" />The visible input has no name: a hidden input named like the field carries the machine
value, and a bubbling input event fires from it whenever that value changes, so a
surrounding phx-change runs. phx-debounce/phx-throttle go to the hidden input.
value may be an integer, a float, a numeric string or a Decimal. The server formats it
for the first paint; a value the server sends later wins over the one in the browser, and
re-rendering the same value does nothing.
Typing keeps what the person writes (digits, the decimal separator, the grouping separator
and a leading - when negatives are allowed); leaving the field clamps it to min/max,
rounds it to decimals/max_decimals and writes it grouped. Arrow up and down (and the
steppers) move by step, Page up and down by ten steps.
The behavior lives in the LineaUI.NumberInput hook, so the field needs a stable id (it
gets one from field or name).
Summary
Functions
Renders the number input.
Functions
Renders the number input.
Events: none of its own. The hidden input dispatches a bubbling input event when the
machine value changes, so the form's phx-change receives %{"name" => "1234.56"}
("" when the field is emptied; the typed text when it is not a number, so the server can
reject it).
Attributes
id(:string) - The visible input's id. Defaults to the field id, thenname.name(:string) - Defaults to the field name.value(:any) - A number, a numeric string or aDecimal. Defaults to the field value.field(Phoenix.HTML.FormField) - A form field: fillsid,name,valueanderrors. Defaults tonil.label(:string) - The caption. Defaults tonil.label_class(:any) - Classes of the caption text. Defaults tonil.help(:string) - The small line under the control. Defaults tonil.errors(:list) - Defaults to[].disabled(:boolean) - Defaults tofalse.locale(:string) - Picks the separators:pt-BRwrites1.234,56,enwrites1,234.56. Defaults to"pt-BR".decimal_separator(:string) - Overrides the locale's decimal separator. Defaults tonil.thousands_separator(:string) - Overrides the locale's grouping separator;""turns grouping off. Defaults tonil.decimals(:integer) - Always this many decimals (2for money:10shows10,00). Defaults tonil.max_decimals(:integer) - At most this many decimals; fewer are shown as typed. Ignored whendecimalsis set. Defaults tonil.min(:any) - The lowest value; a negative sign can be typed only when it is below zero or absent. Defaults tonil.max(:any) - The highest value. Defaults tonil.step(:any) - What the arrow keys and the steppers add or take away. Defaults to1.steppers(:boolean) -−and+buttons on either side. Defaults tofalse.decrement_label(:string) - The accessible name of−. Defaults to"Decrease".increment_label(:string) - The accessible name of+. Defaults to"Increase".prefix(:string) - A box before the input, likeR$. Defaults tonil.suffix(:string) - A box after the input, like%orun. Defaults tonil.variant(:string) - The input's look, as ininput. 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"left". Must be one of"left","right", or"center".wrapper_class(:any) - Classes of the block around the field. Defaults tonil.class(:any) - Classes of the visible input. Defaults tonil.- Global attributes are accepted. Goes to the visible input, except
phx-debounce/phx-throttle, which go to the hidden one. Supports all globals plus:["autocomplete", "autofocus", "form", "placeholder", "readonly", "required"].