Skip to content

Commit

Permalink
Fixed #15799 - InputNumber unneeded update model on blur
Browse files Browse the repository at this point in the history
  • Loading branch information
mehmetcetin01140 committed Jul 3, 2024
1 parent 20c2080 commit 7b389a2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/app/components/inputnumber/inputnumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 === '-') {
Expand Down Expand Up @@ -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 });
}
}
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 7b389a2

Please sign in to comment.