Skip to content

Commit faf684e

Browse files
committed
fix(date-picker): updae ngModel on outside click, #6471
If we drop down the calendar when input has no value, onBlur gets called but we do not call onTouchCallback which is correct. However if after we click outside the input the model is never validated. This is why we should validate model, in this case, and in onClosing event.
1 parent 90b4b5b commit faf684e

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

projects/igniteui-angular/src/lib/date-picker/date-picker.component.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,8 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
854854
const input = this.getEditElement();
855855
if (input && !(event.event && this.mode === InteractionMode.DropDown)) {
856856
input.focus();
857+
} else {
858+
this._updateValidity();
857859
}
858860
});
859861

@@ -1063,14 +1065,8 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
10631065
this.calculateDate(event.target.value, event.type);
10641066
}
10651067

1066-
this._onTouchedCallback();
10671068
if (this.collapsed) {
1068-
const input = this.readonlyInputDirective || this.editableInputDirective || this.input;
1069-
if (this._ngControl && !this._ngControl.valid) {
1070-
input.valid = IgxInputState.INVALID;
1071-
} else {
1072-
input.valid = IgxInputState.INITIAL;
1073-
}
1069+
this._updateValidity();
10741070
}
10751071
}
10761072

@@ -1336,6 +1332,15 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
13361332
return DatePickerUtil.addPromptCharsEditMode(this.dateFormatParts, this.value, changedValue);
13371333
}
13381334

1335+
private _updateValidity() {
1336+
this._onTouchedCallback();
1337+
const input = this.readonlyInputDirective || this.editableInputDirective || this.input;
1338+
if (this._ngControl && !this._ngControl.valid) {
1339+
input.valid = IgxInputState.INVALID;
1340+
} else {
1341+
input.valid = IgxInputState.INITIAL;
1342+
}
1343+
}
13391344
}
13401345

13411346
/**

projects/igniteui-angular/src/lib/time-picker/time-picker.component.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,8 @@ export class IgxTimePickerComponent implements
941941
const input = this.getEditElement();
942942
if (input && !(event.event && this.mode === InteractionMode.DropDown)) {
943943
input.focus();
944+
} else {
945+
this.updateValidity();
944946
}
945947
});
946948

@@ -2022,13 +2024,8 @@ export class IgxTimePickerComponent implements
20222024
}
20232025
}
20242026

2025-
this._onTouchedCallback();
20262027
if (this.toggleRef.collapsed) {
2027-
if (this._ngControl && !this._ngControl.valid) {
2028-
this._inputDirective.valid = IgxInputState.INVALID;
2029-
} else {
2030-
this._inputDirective.valid = IgxInputState.INITIAL;
2031-
}
2028+
this.updateValidity();
20322029
}
20332030
}
20342031

@@ -2125,6 +2122,15 @@ export class IgxTimePickerComponent implements
21252122
((!showHours || !showMinutes || !showSeconds) && this._amPmPos.has(cursor)) ||
21262123
(!showHours && (!showMinutes || !showSeconds) && this._amPmPos.has(cursor));
21272124
}
2125+
2126+
private updateValidity() {
2127+
this._onTouchedCallback();
2128+
if (this._ngControl && !this._ngControl.valid) {
2129+
this._inputDirective.valid = IgxInputState.INVALID;
2130+
} else {
2131+
this._inputDirective.valid = IgxInputState.INITIAL;
2132+
}
2133+
}
21282134
}
21292135

21302136
/**

0 commit comments

Comments
 (0)