Skip to content

Commit

Permalink
Minuses withing money input value ignored now
Browse files Browse the repository at this point in the history
  • Loading branch information
Explicit12 committed Dec 27, 2024
1 parent 023c8cc commit 0d346e7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ui.form-input-money/utilFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)}`;
}
Expand Down

0 comments on commit 0d346e7

Please sign in to comment.