Skip to content

Commit

Permalink
Fixed #10521 - inputnumber : both prefix and currency Input error
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Sep 7, 2021
1 parent 24a6ca7 commit 8eff7e4
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/app/components/inputnumber/inputnumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,17 +743,22 @@ export class InputNumber implements OnInit,ControlValueAccessor {
let valueLength = inputValue.length;
let index = null;

// remove prefix
let prefixLength = (this.prefixChar || '').length;
inputValue = inputValue.replace(this._prefix, '');
selectionStart = selectionStart - prefixLength;

let char = inputValue.charAt(selectionStart);
if (this.isNumeralChar(char)) {
return;
return selectionStart + prefixLength;
}

//left
let i = selectionStart - 1;
while (i >= 0) {
char = inputValue.charAt(i);
if (this.isNumeralChar(char)) {
index = i;
index = i + prefixLength;
break;
}
else {
Expand All @@ -765,11 +770,11 @@ export class InputNumber implements OnInit,ControlValueAccessor {
this.input.nativeElement.setSelectionRange(index + 1, index + 1);
}
else {
i = selectionStart + 1;
i = selectionStart;
while (i < valueLength) {
char = inputValue.charAt(i);
if (this.isNumeralChar(char)) {
index = i;
index = i + prefixLength;
break;
}
else {
Expand All @@ -781,6 +786,8 @@ export class InputNumber implements OnInit,ControlValueAccessor {
this.input.nativeElement.setSelectionRange(index, index);
}
}

return index || 0;
}

onInputClick() {
Expand Down Expand Up @@ -865,9 +872,8 @@ export class InputNumber implements OnInit,ControlValueAccessor {
if (currentLength === 0) {
this.input.nativeElement.value = newValue;
this.input.nativeElement.setSelectionRange(0, 0);
this.initCursor();
const prefixLength = (this.prefixChar || '').length;
const selectionEnd = prefixLength + insertedValueStr.length;
const index = this.initCursor();
const selectionEnd = index + insertedValueStr.length;
this.input.nativeElement.setSelectionRange(selectionEnd, selectionEnd);
}
else {
Expand Down

0 comments on commit 8eff7e4

Please sign in to comment.