Read comma decimals in the remaining decimal fields

GF
1d ago
+1014-125

Stacked PR. Base is stack/transfer-form-keeps-entries (= head of #5850, which sits on #5833). Review #5833 and #5850 first; once they land, this PR can be retargeted to main and shows only its own part. Includes main with #5938 (calculator button): the decimal fields use its operator row and its rounding helper (fixedAmountText), so there is one rounding for every field.

Problem

#5833 moved every amount field to the shared money field. The remaining decimal fields are still browser number inputs: trade and conversion quantities, loan interest and insurance rates, credit card APR, loan rate changes, and decimal settings (classifier values, categorization thresholds). In Chromium a number input drops a comma decimal, so "1,5" is sent as 15.

What changes

  • decimal_field form builder helper. Built on the money field, without a currency: it reads comma and dot decimals, keeps the field's own precision and min/max, and supports the money field's expressions. Used for quantities, rates, rate changes and decimal settings.
  • Saved amounts are prefilled with the separator of the field's currency (12,50 in a euro field instead of 12.5, also for an English-locale user), the same way amounts are displayed elsewhere and the way the field reads input; covered by styled_form_builder_test and recurring_transactions_controller_test.
  • On a disabled field (for example a fixed-rate loan) the operator buttons are disabled too.
  • Guard test. test/architecture/no_number_inputs_test.rb fails when a decimal input is built as number_field / type="number" or as a hand-built inputmode="decimal" text input. Whole-number inputs (years, months, counts, timeouts) are allowed. The rule is documented in the design system guide and AGENTS.md.

Also in this PR:

  • The classifier's whole-number settings (example and transaction counts, grace periods in days) stay number inputs, as on main, in the same form-field frame as the decimal rows so the column lines up. Only the decimal settings become decimal fields.
  • no_number_inputs_test.rb also fails when a money or decimal field is bound to a whole-number column.
  • On a phone the loan's rate rows and the trade's type/quantity row put each field on its own line.

Effects on other parts of the app

  • Integer fields stay number inputs: year built, mileage, area, term and target months, recurrence counts, rows to skip, AI settings and timeouts. A comma decimal would be wrong there.
  • Submitted values are normalized to a dot decimal as before, so controllers and models are unchanged.
  • Rounding to a field's precision now works on the decimal digits, halves away from zero, for plain numbers and expressions alike (1.005 and 1.005*1 both become 1.01 on a 2-decimal field; before, toFixed gave 1.00 for the expression). The bound check, the goal form, the split and exchange-rate readers and the cost basis total use the same rounding, so what they predict matches what is sent.

Owner decisions

  • Build on #5850 so the decimal fields share the money field's parsing, paste handling and raw value option.
  • Keep #5833, #5850 and #5938 as separate PRs; no calculator code of its own in this one.
  • Integer fields keep the plain number input.

Screenshots

Left: main. Right: this PR. Each image shows the calculator closed, then open with the field focused. Field width and height are measured on desktop and with touch emulation.

New trade

trade_new closed
trade_new open

Loan (interest rate)

loan_edit closed
loan_edit open

Credit card (APR, annual fee)

credit_card_edit closed
credit_card_edit open

Classifier settings

settings_classifier closed
settings_classifier open

Measured changes against main (all other fields keep their size, closed and open):

  • Quantity, price, rate and APR fields keep their outer size; the calculator button takes space inside the field.
  • Classifier settings: the inputs are 144 × 38 px instead of 144 × 34 px, the same compact size as the budget amounts. Saved values show the field's precision (0.70 instead of 0.7).

Validation

  • New and updated tests: styled_form_builder_test, no_number_inputs_test, loans_controller_test (disabled operators on fixed-rate rows), properties_controller_test, recurring_transactions_controller_test, settings/classifiers_controller_test, system tests for loan rate changes, holding cost basis and trades, JS unit tests for the amount helpers.
  • Locally green: JS unit tests (322), architecture, helper and the affected controller tests (701 runs), the affected system tests (31 runs). RuboCop, erb_lint and Biome clean. The full suite runs in CI.
  • Tested by hand in a test deployment.

How this fits together

The money field work is split into small PRs that build on each other. Review from the top of this list; each stacked PR's base is a stack/* copy of the PR below it, so its diff shows only its own change.

  1. #6032: bounds checked on the submitted amount, hints for ignored input, parentheses (fixes #5944). Base: main.
  2. #6033: operator bar docked above the on-screen keyboard. Base: #6032.
  3. #5833: every amount input uses the money field. Base: #6033.
  4. #5850: a rejected transfer keeps its input; comma exchange rates. Base: #5833.
  5. #5939: the remaining decimal fields (quantities, rates) read comma decimals. Base: #5850.
  6. #6035: plain-number fields without the calculator for settings, rates and rule/filter limits. Base: #5939.

Standalone: #6034 (phone layout of goal, vehicle and settings number rows). Base: main; it does not depend on the stack.

Summary by CodeRabbit

  • New Features

    • Added decimal input fields for rates, quantities, and other non-currency values, with locale-aware formatting and up to 18 decimal places where applicable.
    • Decimal fields accept comma separators and leading-decimal entries.
    • Updated loan rate and trade field layouts for smaller screens.
  • Bug Fixes

    • Improved decimal value handling during form submission, including when JavaScript is unavailable.
    • Improved validation and calculations for trade quantities, cost basis, loan rates, and decimal settings.
    • Invalid exponent-form entries remain visible and are clearly flagged as invalid.