From 32cddd4b594c18774f6f474b9a38ef47a60580bf Mon Sep 17 00:00:00 2001 From: mertsincan Date: Mon, 6 Sep 2021 14:54:46 +0300 Subject: [PATCH] Fixed #10583 - Add allowEmpty property to InputNumber --- src/app/components/inputnumber/inputnumber.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/components/inputnumber/inputnumber.ts b/src/app/components/inputnumber/inputnumber.ts index a31e0102c06..4f8921009cc 100755 --- a/src/app/components/inputnumber/inputnumber.ts +++ b/src/app/components/inputnumber/inputnumber.ts @@ -90,6 +90,8 @@ export class InputNumber implements OnInit,ControlValueAccessor { @Input() step: number = 1; + @Input() allowEmpty: boolean = true; + @Input() inputStyle: any; @Input() inputStyleClass: string; @@ -885,6 +887,7 @@ export class InputNumber implements OnInit,ControlValueAccessor { if (valueStr != null) { newValue = this.parseValue(valueStr); + newValue = !newValue && !this.allowEmpty ? 0 : newValue; this.updateInput(newValue, insertedValueStr, operation, valueStr); this.handleOnInput(event, currentValue, newValue); @@ -1045,7 +1048,8 @@ export class InputNumber implements OnInit,ControlValueAccessor { } formattedValue() { - return this.formatValue(this.value); + const val = !this.value && !this.allowEmpty ? 0 : this.value; + return this.formatValue(val); } updateModel(event, value) {