Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deleting 5 after entering say 500 causes everything to be deleted #1355

Open
tedp opened this issue Apr 18, 2024 · 1 comment
Open

Deleting 5 after entering say 500 causes everything to be deleted #1355

tedp opened this issue Apr 18, 2024 · 1 comment

Comments

@tedp
Copy link

tedp commented Apr 18, 2024

馃悶 bug report

Is this a regression?

Not sure

Description

Deleting first number where the number is in the hundreds causes the whole number to be deleted apart from 0. This is not the case for example where the number is in the thousands

馃敩 Minimal Reproduction

Using your own example https://jsdaddy.github.io/ngx-mask/#1 where the mask is set to 'separator.2' for example, enter the number 500 then delete the first number 5. You will see that the whole number is deleted leaving just 0.

If you try the same for 5000 then only the number 5 is deleted as expected

Also if you try 555 and delete the first 5 then this also works as expected

Anything else relevant?

I've tried in both Chrome and Edge on a Mac

@smartredfox
Copy link

It looks like the check to see if a decimal separator needs to be added needs an additional check to see if it's a zero, otherwise it adds a second decimal - this then causes issues when the later formatters run. The same issue occurs for any number where the next digit is a zero (505,000 for example becomes 0.50 when you delete the first 5).

This seems to fix it:

                if (inputValue[0] === "0" /* MaskExpression.NUMBER_ZERO */ &&
                    inputValue[1] !== "0" && /*This seems to fix it */
                    inputValue[1] !== decimalMarker &&
                    inputValue[1] !== this.thousandSeparator) {
                    // eslint-disable-next-line no-param-reassign
                    inputValue =
                        inputValue.length > 1
                            ? inputValue.slice(0, 1) +
                                decimalMarker +
                                inputValue.slice(1, inputValue.length + 1)
                            : inputValue;
                    this.plusOnePosition = true;
                }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants