diff --git a/frontend/src/lib/components/apps/components/inputs/currency/AppCurrencyInput.svelte b/frontend/src/lib/components/apps/components/inputs/currency/AppCurrencyInput.svelte index 9b38abf63c..03d2a6816c 100644 --- a/frontend/src/lib/components/apps/components/inputs/currency/AppCurrencyInput.svelte +++ b/frontend/src/lib/components/apps/components/inputs/currency/AppCurrencyInput.svelte @@ -102,7 +102,7 @@ 'wm-currency-input' ), wrapper: 'w-full windmillapp', - formattedZero: twMerge('text-black windmillapp ', css?.input?.class, 'wm-currency') + formattedZero: twMerge('windmillapp ', css?.input?.class, 'wm-currency') }} style={css?.input?.style} bind:value diff --git a/frontend/src/lib/components/apps/components/inputs/currency/CurrencyInput.svelte b/frontend/src/lib/components/apps/components/inputs/currency/CurrencyInput.svelte index 8634cf2863..e200704ad4 100644 --- a/frontend/src/lib/components/apps/components/inputs/currency/CurrencyInput.svelte +++ b/frontend/src/lib/components/apps/components/inputs/currency/CurrencyInput.svelte @@ -43,12 +43,17 @@ maximumFractionDigits?: number, minimumFractionDigits?: number ) => { - return new Intl.NumberFormat(locale, { - currency: currency, - style: 'currency', - maximumFractionDigits: maximumFractionDigits || 0, - minimumFractionDigits: minimumFractionDigits || 0 - }).format(value) + try { + return new Intl.NumberFormat(locale, { + currency: currency, + style: 'currency', + maximumFractionDigits: maximumFractionDigits || 0, + minimumFractionDigits: minimumFractionDigits || 0 + }).format(value) + } catch (e) { + console.error(e) + return 'ERR' + } } // Checks if the key pressed is allowed @@ -64,14 +69,15 @@ } let inputTarget: HTMLInputElement - const currencyDecimal = new Intl.NumberFormat(locale).format(1.1).charAt(1) // '.' or ',' - const isDecimalComma = currencyDecimal === ',' - const currencySymbol = formatCurrency(0, 0) - .replace('0', '') // e.g. '$0' > '$' - .replace(/\u00A0/, '') // e.g '0 €' > '€' // Updates `value` by stripping away the currency formatting const setUnformattedValue = (event?: KeyboardEvent) => { + const currencyDecimal = new Intl.NumberFormat(locale).format(1.1).charAt(1) // '.' or ',' + const isDecimalComma = currencyDecimal === ',' + const currencySymbol = formatCurrency(0, 0) + .replace('0', '') // e.g. '$0' > '$' + .replace(/\u00A0/, '') // e.g '0 €' > '€' + if (event) { // Don't format if the user is typing a `currencyDecimal` point if (event.key === currencyDecimal) return @@ -189,7 +195,7 @@ /> -