Skip to content

Commit

Permalink
Fix primefaces#2871: InputNumber duplicating suffix when using decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Nov 11, 2022
1 parent 9b4a1d4 commit 825ccb3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions components/lib/inputnumber/InputNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,9 +889,13 @@ export const InputNumber = React.memo(
if (val1 && val2) {
let decimalCharIndex = val2.search(_decimal.current);

if (decimalCharIndex === -1) {
return val1;
}

_decimal.current.lastIndex = 0;

return decimalCharIndex !== -1 ? val1.split(_decimal.current)[0] + val2.slice(decimalCharIndex) : val1;
return decimalCharIndex !== -1 ? replaceSuffix(val1.split(_decimal.current)[0]) + val2.slice(decimalCharIndex) : val1;
}

return val1;
Expand All @@ -902,13 +906,21 @@ export const InputNumber = React.memo(
const valueSplit = value.split(_decimal.current);

if (valueSplit.length === 2) {
return valueSplit[1].replace(_suffix.current, '').trim().replace(/\s/g, '').replace(_currency.current, '').length;
return replaceSuffix(valueSplit[1]).length;
}
}

return 0;
};

const replaceSuffix = (value) => {
if (!value) {
return value;
}

return value.replace(_suffix.current, '').trim().replace(/\s/g, '').replace(_currency.current, '');
};

const updateModel = (event, value) => {
if (props.onValueChange) {
props.onValueChange({
Expand Down

0 comments on commit 825ccb3

Please sign in to comment.