Skip to content

PhoenixKit 2.26.0: A decimal input that takes a comma or a dot

PhoenixKit 2.26.0 gives modules and apps a form field for prices, quantities, weights and lengths in which a comma and a dot both work as the decimal point and nothing is rounded.

Why a new field

The browser’s own number field causes trouble on multilingual sites. Its decimal separator follows the page language, so on an Estonian page a typed 2.5 can be dropped and the field sends nothing, while on an English page 2,5 is dropped instead. Its step setting makes any other precision invalid and quietly blocks the form from being sent, and its arrows take over the mouse wheel and arrow keys.

Decimal input

The new <.decimal_input> component is a plain text field that opens the decimal keyboard on phones. The server decides what the text means. It can show a unit inside the field, such as kg, and keeps the text a person typed unchanged when the form updates, so 2,5 does not turn into 2.5 under the cursor. Otherwise it works like <.input>: it binds to a form field or a plain name and value, and has a label, translated errors and the required marker.

Reading typed numbers

PhoenixKit.Utils.Number.parse_decimal/2 turns typed text into an exact decimal. A comma or a dot is the decimal point. Spaces, dots or commas are accepted as thousands separators only between groups of three digits, so "12 34" is refused rather than read as 1234. Minimum and maximum limits are checked, never clamped, and the answer says whether the value was empty, invalid, too low or too high. Exponents, NaN, hex, values of 10¹² or more and input longer than 64 bytes are refused. A negative zero is returned without its sign, so the field never shows -0.

Upgrading

No migration and no configuration. Nothing changes on a site until a module or the app uses the new component.

Full release notes: PhoenixKit 2.26.0

2.26.0 · 16 September 2026

Added

  • <.decimal_input> (PhoenixKitWeb.Components.Core.DecimalInput) — a form control for quantities, prices and measurements, where a comma and a dot must both work and nothing may be rounded. It renders type="text" inputmode="decimal" in place of a browser number control, whose separator follows the page locale and whose step blocks submits. It takes an optional unit suffix, and the text a person typed survives a re-render unchanged. Otherwise it matches <.input>: FormField or raw name/value, label, translated errors, class / wrapper_class. (#818)
  • PhoenixKit.Utils.Number.parse_decimal/2 (plus parse_decimal!/2 and format_decimal/1) — turns typed text into a normalized Decimal. A comma or a dot is the decimal point, and space / dot / comma grouping is accepted only between 3-digit groups. It takes :min / :max and never clamps. Exponents, NaN, hex and values of 10¹² or more are refused, and input over 64 bytes is rejected before any parsing. It returns {:error, :empty | :invalid | :below_min | :above_max}. (#818)

Fixed

  • Post-merge review of #818: space grouping is now held to the same 3-digit rule as dot/comma grouping ("12 34" and "1,234 567" were silently merged into 1234 and 1.234567), and a negative zero is returned unsigned so the field never shows -0.

PhoenixKit 2.26.0. Install or update: {:phoenix_kit, "~> 2.26"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.