mirror of
https://github.com/we-promise/sure.git
synced 2026-04-12 00:27:21 +00:00
Fix French decimal separator handling in money input fields
Number.parseFloat() only recognizes dots as decimal separators, causing inputs like "256,54" (French locale) to be parsed as "256". Added a parseLocaleFloat utility that detects whether comma or dot is the decimal separator and normalizes accordingly before parsing. Fixes #1138 https://claude.ai/code/session_01ThfszjiCmbDDPyb4TZqk2X
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Controller } from "@hotwired/stimulus";
|
||||
import parseLocaleFloat from "utils/parse_locale_float";
|
||||
import { CurrenciesService } from "services/currencies_service";
|
||||
|
||||
// Connects to data-controller="money-field"
|
||||
@@ -15,10 +16,9 @@ export default class extends Controller {
|
||||
new CurrenciesService().get(currency).then((currency) => {
|
||||
this.amountTarget.step = currency.step;
|
||||
|
||||
if (Number.isFinite(this.amountTarget.value)) {
|
||||
this.amountTarget.value = Number.parseFloat(
|
||||
this.amountTarget.value,
|
||||
).toFixed(currency.default_precision);
|
||||
const parsedAmount = parseLocaleFloat(this.amountTarget.value);
|
||||
if (Number.isFinite(parsedAmount)) {
|
||||
this.amountTarget.value = parsedAmount.toFixed(currency.default_precision);
|
||||
}
|
||||
|
||||
this.symbolTarget.innerText = currency.symbol;
|
||||
|
||||
Reference in New Issue
Block a user