From 0d346e76db656b3d39a70c210a0827da841ac749 Mon Sep 17 00:00:00 2001 From: Explicit12 Date: Thu, 26 Dec 2024 23:16:32 +0200 Subject: [PATCH] Minuses withing money input value ignored now --- src/ui.form-input-money/utilFormat.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ui.form-input-money/utilFormat.ts b/src/ui.form-input-money/utilFormat.ts index cf194ab6..1d7ae827 100644 --- a/src/ui.form-input-money/utilFormat.ts +++ b/src/ui.form-input-money/utilFormat.ts @@ -30,7 +30,7 @@ export function getFormattedValue(value: string | number, options: FormatOptions } = options; const invalidValuesRegExp = new RegExp("[^\\d,\\d.\\s-" + decimalSeparator + "]", "g"); - const doubleValueRegExp = new RegExp("([,\\.\\s-" + decimalSeparator + "])+", "g"); + const doubleValueRegExp = new RegExp("([,\\.\\s" + decimalSeparator + "])+", "g"); // slice to first decimal mark value = String(value) @@ -51,11 +51,16 @@ export function getFormattedValue(value: string | number, options: FormatOptions const isNumber = isNumberValueRegExp.test(value); const isFloat = value.endsWith(rawDecimalMark) || value.endsWith(".0"); const isMinus = value === minus; + const isMinusWithin = value.includes(minus) && !value.startsWith(minus); if (isMinus && positiveOnly) { value = ""; } + if (isMinusWithin) { + value = value.replaceAll(minus, ""); + } + if (!value || !isNumber || isFloat || isMinus) { return `${prefix}${value.replaceAll(rawDecimalMark, decimalSeparator)}`; }