mirror of
https://github.com/we-promise/sure.git
synced 2026-04-09 07:14:47 +00:00
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
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user