From ef4750c2c578b5c7158a1fc514cd4d9d2ca2994f Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 10 Mar 2026 17:15:44 +0000 Subject: [PATCH] Skip reformatting blank amount fields on currency change parseLocaleFloat returns 0 for empty strings, which caused blank amount fields to be overwritten with "0.00" when the user changed currency. Guard against this by checking for a non-empty value before parsing. https://claude.ai/code/session_01ThfszjiCmbDDPyb4TZqk2X --- app/javascript/controllers/money_field_controller.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/javascript/controllers/money_field_controller.js b/app/javascript/controllers/money_field_controller.js index ac77008e5..686ca713a 100644 --- a/app/javascript/controllers/money_field_controller.js +++ b/app/javascript/controllers/money_field_controller.js @@ -16,9 +16,12 @@ export default class extends Controller { new CurrenciesService().get(currency).then((currency) => { this.amountTarget.step = currency.step; - const parsedAmount = parseLocaleFloat(this.amountTarget.value); - if (Number.isFinite(parsedAmount)) { - this.amountTarget.value = parsedAmount.toFixed(currency.default_precision); + const rawValue = this.amountTarget.value.trim(); + if (rawValue !== "") { + const parsedAmount = parseLocaleFloat(rawValue); + if (Number.isFinite(parsedAmount)) { + this.amountTarget.value = parsedAmount.toFixed(currency.default_precision); + } } this.symbolTarget.innerText = currency.symbol;