From 8eff7e4e680acf4f272f18643ebeaaf9ccc8f14d Mon Sep 17 00:00:00 2001 From: mertsincan Date: Tue, 7 Sep 2021 11:12:51 +0300 Subject: [PATCH] Fixed #10521 - inputnumber : both prefix and currency Input error --- src/app/components/inputnumber/inputnumber.ts | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/app/components/inputnumber/inputnumber.ts b/src/app/components/inputnumber/inputnumber.ts index fdbe4db7a2a..88501d5cb50 100755 --- a/src/app/components/inputnumber/inputnumber.ts +++ b/src/app/components/inputnumber/inputnumber.ts @@ -743,9 +743,14 @@ 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 @@ -753,7 +758,7 @@ export class InputNumber implements OnInit,ControlValueAccessor { while (i >= 0) { char = inputValue.charAt(i); if (this.isNumeralChar(char)) { - index = i; + index = i + prefixLength; break; } else { @@ -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 { @@ -781,6 +786,8 @@ export class InputNumber implements OnInit,ControlValueAccessor { this.input.nativeElement.setSelectionRange(index, index); } } + + return index || 0; } onInputClick() { @@ -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 {