You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When programmatically setting the input value and then manually modifying a number input with negative number support, the cursor jumps before the negative sign.
When not setting the input programmatically, it works as expected.
form = this.formBuilder.group({
input1: this.formBuilder.control(42),
})
How to reproduce
Set the value of the control programmatically (for example: input1: this.formBuilder.control(42)).
Clear the input by hand.
Type the negative sign (-).
The cursor will jump to before the negative sign automatically:
This causes that if you write more than one character (-1), then the negative sign will be removed and the value will be 1.
A gif of the bug:
Keys pressed:
Mouse left click in the input.
Backspace.
Backspace.
Negative sign (-).
1.
Expected
I don't want the cursor to jump.
Debug
I debugged it a little, but I don't know the library enough to create a PR for this bug.
As I see it, the programmatic value change calls the MaskDirective.writeValue method which sets this._maskService.isNumberValue = true;.
When manually modifying the value, the MaskService._checkSymbols('-') method will try to parse the input as a number (return Number(separatorValue);) which will return NaN, and this somehow causes the cursor jump.
Workaround
If somebody else has this error too, set [dropSpecialCharacters]="false" and parse the string output of ngx-mask yourself.
Same happens for round braces, after typing when I continuously click the backspace button to erase everything, the symbol on the first location is jumped from backspace.
Regex
(000) 0000 0000
After placing backspace
from '(0|' to '|(' in single backspace.
Here, consider '|' as the cursor
When programmatically setting the input value and then manually modifying a number input with negative number support, the cursor jumps before the negative sign.
When not setting the input programmatically, it works as expected.
Version info
Angular: 9.1.9
ngx-mask: 9.1.2
Minimal reproduction demo
https://stackblitz.com/edit/ngx-mask-negative-number-cursor-jump-bug
or
HTML:
TypeScript:
How to reproduce
input1: this.formBuilder.control(42)
).-
).The cursor will jump to before the negative sign automatically:
This causes that if you write more than one character (
-1
), then the negative sign will be removed and the value will be1
.A gif of the bug:
Keys pressed:
-
).1
.Expected
I don't want the cursor to jump.
Debug
I debugged it a little, but I don't know the library enough to create a PR for this bug.
As I see it, the programmatic value change calls the
MaskDirective.writeValue
method which setsthis._maskService.isNumberValue = true;
.When manually modifying the value, the
MaskService._checkSymbols('-')
method will try to parse the input as a number (return Number(separatorValue);
) which will returnNaN
, and this somehow causes the cursor jump.Workaround
If somebody else has this error too, set
[dropSpecialCharacters]="false"
and parse the string output ofngx-mask
yourself.Duplicate
This issue may be a duplicate of #736.
The text was updated successfully, but these errors were encountered: