Skip to content

Commit

Permalink
Fixed #12426 - InputMask | numbers entered in the middle of the field…
Browse files Browse the repository at this point in the history
…, get moved to the left
  • Loading branch information
cetincakiroglu committed Jan 3, 2023
1 parent 1221d24 commit 5aa6db3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/app/components/inputmask/inputmask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export class InputMask implements OnInit, ControlValueAccessor {

@Input() autocomplete: string;

@Input() keepBuffer: boolean = false;

@ViewChild('input', { static: true }) inputViewChild: ElementRef;

@Output() onComplete: EventEmitter<any> = new EventEmitter();
Expand Down Expand Up @@ -523,10 +525,12 @@ export class InputMask implements OnInit, ControlValueAccessor {
}

clearBuffer(start, end) {
let i;
for (i = start; i < end && i < this.len; i++) {
if (this.tests[i]) {
this.buffer[i] = this.getPlaceholder(i);
if (!this.keepBuffer) {
let i;
for (i = start; i < end && i < this.len; i++) {
if (this.tests[i]) {
this.buffer[i] = this.getPlaceholder(i);
}
}
}
}
Expand All @@ -549,7 +553,7 @@ export class InputMask implements OnInit, ControlValueAccessor {
while (pos++ < test.length) {
c = test.charAt(pos - 1);
if (this.tests[i].test(c)) {
this.buffer[i] = c;
// this.buffer[i] = c;
lastMatch = i;
break;
}
Expand Down Expand Up @@ -599,7 +603,7 @@ export class InputMask implements OnInit, ControlValueAccessor {

this.focusText = this.inputViewChild.nativeElement.value;

pos = this.checkVal();
pos = this.keepBuffer ? this.inputViewChild.nativeElement.value.length - 1 : this.checkVal();

this.caretTimeoutId = setTimeout(() => {
if (this.inputViewChild.nativeElement !== this.inputViewChild.nativeElement.ownerDocument.activeElement) {
Expand Down

0 comments on commit 5aa6db3

Please sign in to comment.