Skip to content

Commit

Permalink
Fixed #10866 - readonly not working on p-inputNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
yigitfindikli committed Nov 22, 2021
1 parent 00d8955 commit 4f32ed6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/app/components/inputnumber/inputnumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,21 @@ export class InputNumber implements OnInit,ControlValueAccessor {
}

onUserInput(event) {
if(this.readonly) {
return;
}

if (this.isSpecialChar) {
event.target.value = this.lastValue;
}
this.isSpecialChar = false;
}

onInputKeyDown(event) {
if(this.readonly) {
return;
}

this.lastValue = event.target.value;
if (event.shiftKey || event.altKey) {
this.isSpecialChar = true;
Expand Down Expand Up @@ -573,6 +581,10 @@ export class InputNumber implements OnInit,ControlValueAccessor {
}

onInputKeyPress(event) {
if (this.readonly) {
return;
}

event.preventDefault();
let code = event.which || event.keyCode;
let char = String.fromCharCode(code);
Expand All @@ -585,7 +597,7 @@ export class InputNumber implements OnInit,ControlValueAccessor {
}

onPaste(event) {
if (!this.disabled) {
if (!this.disabled && !this.readonly) {
event.preventDefault();
let data = (event.clipboardData || window['clipboardData']).getData('Text');
if (data) {
Expand Down Expand Up @@ -793,7 +805,9 @@ export class InputNumber implements OnInit,ControlValueAccessor {
}

onInputClick() {
this.initCursor();
if(!this.readonly) {
this.initCursor();
}
}

isNumeralChar(char) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/showcase/components/inputnumber/inputnumberdemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ export class InputNumberDemo {
value19: number = 25;

value20: number = 50;
}
}

0 comments on commit 4f32ed6

Please sign in to comment.