Open the money field's operator row from a calculator button
Merged
GF
7d ago+1052+1052+0123456789012345678901234567890123456789-75-75-01234567890123456789
Problem
Amount fields can calculate expressions such as 12.50+4.30 (#3502). The +/−/×/÷ row added for that opened as soon as the field had focus, on every device. It was absolutely positioned under the field and covered the start of the next field. On a computer the keyboard already has the operators, so the row was mostly in the way. On a phone it is needed, because the decimal keypad has no operator keys.
What changes
- Calculator button in the field. The operator row opens and closes from a calculator icon next to the currency. It opens inside the field (no overlap with the next field) and only while the field has focus. While closed it is
inert, so its buttons are not in the Tab order. - The choice is remembered per device (localStorage, with an in-memory fallback) and shared by every money field on the page. People who want a plain amount field keep it closed everywhere.
- "=" button evaluates the expression in place, without leaving the field. It also reacts to a click without a press (assistive technology). On touch screens the operator and "=" buttons are 44px high.
- Live result. While an expression is typed, its result shows in a reserved slot next to the amount (
= 16.80). A plain number, an empty field or an invalid expression shows nothing, and the slot keeps its width so nothing shifts. In a narrow field (container query, below 24rem) the result moves to its own line so long expressions get the full width. - Example placeholder. With the row closed the field keeps its normal placeholder. With the row open, an empty field that uses the default placeholder shows an example in the field's own format (
e.g. 12.50+4.30,12,50+4,30for comma currencies,1250+430for zero-decimal currencies), and it follows a currency switch. A caller's own placeholder (such as "blank: whole balance" in goals) is kept. - Overflow cue. When the start of a long expression scrolls out of view, the input's left edge fades. The text stays scrollable and editable with the cursor, a click or a swipe.
- No lost clicks. Closing the row shifts the content below. When focus leaves because of a mouse press or a touch tap, the row and the result line wait for that click before they change, also while the press is held.
- Turbo morph. After a morph resets the field's markup, the controller applies the open row, placeholder and result again.
Effects on other parts of the app
- Only the shared money field partial and its Stimulus controller change. Every money field gets the button (18 forms: transactions, trades, transfers, valuations, goals, budgets, loans, properties, holdings and others). On a disabled money field the button and the operator row are disabled too.
- No change to how amounts are parsed, validated or submitted. Balances, reports, syncs and jobs are not affected.
isAmountExpressionis a new pure helper next toevaluateAmountExpression. - New translation keys in
en,de,es,fr,id,nb,nlandzh-CN(calculator_show,calculator_hide,operator_equals,expression_placeholder). The German file also gets the existing money field keys that were missing.
Screenshots (demo data)
| Before (main) | After |
|---|---|
![]() | ![]() |
| Focused amount: the row opens at once and covers "Category". | Focused amount: compact field with the calculator button. |
![]() | ![]() |
| Typing an expression. | Row opened from the button, live result, "=" button. |
![]() | ![]() |
| Phone width, long expression. | Phone width: result on its own line, faded left edge. |
More: open row, empty, after "=".
Owner decisions
- Out of five layout options (delay, calculator icon, touch only, no buttons, popover keypad) the calculator icon was chosen, because it keeps the row discoverable without popping up on its own.
- Kept: remembered open state, live result, "=" button, smooth opening, example placeholder. Dropped: showing the icon only while focused, and a tooltip on the icon.
- After feedback from a maintainer on Discord: the result shows only for an expression (reserved but empty otherwise), the example placeholder only while the row is open, and on narrow fields the result takes its own line.
- Long expressions stay on one line with a faded left edge, instead of a multi-line field (which would change the input in every form).
Findings from manual testing
- The calculator button and the closed operator row made every money field 4–8 px taller. The button takes back its extra height and the closed row the field body's gap, so the field keeps its old height (62 px measured before and after).
- The result vanished at each operator press, because "12+4+" does not evaluate. The preview now shows the result of the finished part.
- Only digits, separators, operators and spaces can be typed or dropped into the amount; paste keeps its own parsing.
- Amounts were rounded with
toFixed, which rounds the binary value (12,505+4,3 gave 16,80, 1,005 gave 1,00). They are now rounded as written, halves away from zero, in the preview, on blur, paste and submit. - Checked in the browser across 13 currencies (incl. JPY/HUF without decimals and KWD with three) and with HTML/script text: the preview is set as text only.
Validation
- New system tests
test/system/money_field_calculator_test.rb(closed by default, opens from the button, live result only for expressions, "=" evaluates in place, choice remembered across pages and shared with other money fields on the page, button opens the row when the saved choice is open but the field is unfocused, comma and zero-decimal examples and results after a currency switch, a caller's placeholder is kept, the row comes back after a morph, "=" on a click without a press, a held press keeps the row and the result). Each test added for a review finding fails without its fix. - Updated
test/system/money_field_operators_test.rbfor the button and the new Tab order (amount → calculator button → currency → operators). - Unit tests for
isAmountExpressionandformatFixedAmountintest/javascript/evaluate_amount_expression_test.mjs(node --test test/javascript/*.mjs). - Money field system tests (transactions, trades, transfers, splits, goals, holdings cost basis, property, accounts, recurring, conversions): green locally.
- RuboCop, erb_lint, Biome lint and Brakeman: clean. The full suite runs in CI.
- Updated controller tests for the new markup (
goals_controller_test,holdings_controller_test). - Code review and security review before opening, plus a review round on the calculator in a test deployment.
Summary by cubic
Turns the money field's +/−/×/÷ row into an opt-in calculator opened from a button inside the field, so it no longer opens on focus and no longer overlaps the field below. Parsing, validation and submission are unchanged.
- The operator row opens and closes from a calculator button in the field, only while the field has focus, and the open/closed choice is remembered per device and shared by every money field on the page.
- While an expression is typed, its result shows in a reserved slot next to the amount; on narrow fields it moves to its own line, and long expressions fade at the input's left edge.
- With the row open, an empty field with the default placeholder shows a currency-formatted example; caller-provided placeholders are kept.
- "=" evaluates the expression in place, and the operator and "=" buttons also respond to clicks without a press (assistive technology) without double-inserting.
- Closing the row after focus leaves waits for a pending pointer click so the layout shift doesn't swallow it, and the state is reapplied after a Turbo morph.
- Typed and dropped input is restricted to digits, separators, operators and spaces; ×, ÷, −, the en dash and the letter x are entered as the operators they mean, so typing "12×4" or "12x4" no longer submits 124.
- Amounts are rounded as written, halves away from zero; a typed plain number rounds on its own digits, so one with more digits than a JS number stores (e.g. "1.00499…9" that reads as 1.005) still rounds to 1.00. Expression sums, products and terminating quotients settle to their operands' decimal places (0.35/10 rounds like 0.35×0.1), and trailing zeros add none. Bounds checks and the goal form use the same rounding.
- A disabled amount field disables the button and the whole operator row.
- The field keeps its resting height, including on touch screens where the button's tap target grows to 44px. A click alone on the button with focus outside the field focuses it so the opened row is not inert. New translations are added in nine languages, including
pt-BR.
Summary by CodeRabbit
- New Features
- Added an optional calculator to money fields, with operator buttons, expression previews, and one-click evaluation.
- The calculator follows the focused field and remembers its open or closed setting across fields and visits. Its controls support keyboard and assistive-technology activation.
- Added example placeholders and filtering for unsupported input characters. Existing placeholders and amount limits are preserved, and calculator controls are disabled when the field is disabled.
- Added translated calculator labels and placeholders across supported languages.
- Bug Fixes
- Improved fixed-precision rounding for calculations and amount-bound checks, including half values and very large or exponent-form amounts. Recognized operator variants are normalized, and terminating division results retain their decimal precision.





