diff --git a/src/app/components/inputnumber/inputnumber.ts b/src/app/components/inputnumber/inputnumber.ts index 7dca44d2a95..574b1389005 100644 --- a/src/app/components/inputnumber/inputnumber.ts +++ b/src/app/components/inputnumber/inputnumber.ts @@ -597,6 +597,7 @@ export class InputNumber implements OnInit, AfterContentInit, OnChanges, Control const decimalChar = this.getDecimalChar(); return new RegExp(`[${decimalChar}]`, 'g'); } + getDecimalChar(): string { const formatter = new Intl.NumberFormat(this.locale, { ...this.getOptions(), useGrouping: false }); return formatter @@ -648,6 +649,10 @@ export class InputNumber implements OnInit, AfterContentInit, OnChanges, Control return new RegExp(`${this.escapeRegExp(this.suffixChar || '')}`, 'g'); } + get isBlurUpdateOnMode() { + return this.ngControl?.control?.updateOn === 'blur'; + } + formatValue(value: any) { if (value != null) { if (value === '-') { @@ -1281,7 +1286,7 @@ export class InputNumber implements OnInit, AfterContentInit, OnChanges, Control if (this.isValueChanged(currentValue, newValue)) { (this.input as ElementRef).nativeElement.value = this.formatValue(newValue); this.input?.nativeElement.setAttribute('aria-valuenow', newValue); - this.updateModel(event, newValue); + !this.isBlurUpdateOnMode && this.updateModel(event, newValue); this.onInput.emit({ originalEvent: event, value: newValue, formattedValue: currentValue }); } } @@ -1446,16 +1451,14 @@ export class InputNumber implements OnInit, AfterContentInit, OnChanges, Control } updateModel(event: Event, value: any) { - const isBlurUpdateOnMode = this.ngControl?.control?.updateOn === 'blur'; - if (this.value !== value) { this.value = value; - if (!(isBlurUpdateOnMode && this.focused)) { + if (!(this.isBlurUpdateOnMode && this.focused)) { + this.onModelChange(value); + } else if (this.isBlurUpdateOnMode) { this.onModelChange(value); } - } else if (isBlurUpdateOnMode) { - this.onModelChange(value); } this.onModelTouched(); }