From 7b389a2b66427a14bb14bf2f379ab8876b9a94fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mehmet=20=C3=87etin?= <92744169+mehmetcetin01140@users.noreply.github.com> Date: Wed, 3 Jul 2024 11:06:28 +0300 Subject: [PATCH] Fixed #15799 - InputNumber unneeded update model on blur --- src/app/components/inputnumber/inputnumber.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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(); }