Skip to content

Commit 0e16cb2

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. # Conflicts: # projects/igniteui-angular/src/lib/time-picker/time-picker.component.ts
1 parent 6b0b7d9 commit 0e16cb2

File tree

2 files changed

+49
-13
lines changed

2 files changed

+49
-13
lines changed

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

+12-7
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,8 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
907907
const input = this.getEditElement();
908908
if (input && !(event.event && this.mode === InteractionMode.DropDown)) {
909909
input.focus();
910+
} else {
911+
this._updateValidity();
910912
}
911913
});
912914

@@ -1135,14 +1137,8 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
11351137
this.calculateDate(event.target.value, event.type);
11361138
}
11371139

1138-
this._onTouchedCallback();
11391140
if (this.collapsed) {
1140-
const input = this.readonlyInputDirective || this.editableInputDirective || this.input;
1141-
if (this._ngControl && !this._ngControl.valid) {
1142-
input.valid = IgxInputState.INVALID;
1143-
} else {
1144-
input.valid = IgxInputState.INITIAL;
1145-
}
1141+
this._updateValidity();
11461142
}
11471143
}
11481144

@@ -1426,6 +1422,15 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
14261422
return DatePickerUtil.addPromptCharsEditMode(this.dateFormatParts, this.value, changedValue);
14271423
}
14281424

1425+
private _updateValidity() {
1426+
this._onTouchedCallback();
1427+
const input = this.readonlyInputDirective || this.editableInputDirective || this.input;
1428+
if (this._ngControl && !this._ngControl.valid) {
1429+
input.valid = IgxInputState.INVALID;
1430+
} else {
1431+
input.valid = IgxInputState.INITIAL;
1432+
}
1433+
}
14291434
}
14301435

14311436
/**

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

+37-6
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,8 @@ export class IgxTimePickerComponent implements
873873
const input = this.getEditElement();
874874
if (input && !(event.event && this.mode === InteractionMode.DropDown)) {
875875
input.focus();
876+
} else {
877+
this.updateValidity();
876878
}
877879
});
878880

@@ -1824,13 +1826,8 @@ export class IgxTimePickerComponent implements
18241826
}
18251827
}
18261828

1827-
this._onTouchedCallback();
18281829
if (this.toggleRef.collapsed) {
1829-
if (this._ngControl && !this._ngControl.valid) {
1830-
this._inputDirective.valid = IgxInputState.INVALID;
1831-
} else {
1832-
this._inputDirective.valid = IgxInputState.INITIAL;
1833-
}
1830+
this.updateValidity();
18341831
}
18351832
}
18361833

@@ -1905,6 +1902,40 @@ export class IgxTimePickerComponent implements
19051902
this._setCursorPosition(cursor);
19061903
});
19071904
}
1905+
1906+
private cursorOnHours(cursor: number, showHours: boolean): boolean {
1907+
return showHours && this._hoursPos.has(cursor);
1908+
}
1909+
1910+
private cursorOnMinutes(cursor: number, showHours: boolean, showMinutes: boolean): boolean {
1911+
return showMinutes &&
1912+
(showHours && this._minutesPos.has(cursor)) ||
1913+
(!showHours && this._minutesPos.has(cursor));
1914+
}
1915+
1916+
private cursorOnSeconds(cursor: number, showHours: boolean, showMinutes: boolean, showSeconds: boolean): boolean {
1917+
return showSeconds &&
1918+
(showHours && showMinutes && this._secondsPos.has(cursor)) ||
1919+
((!showHours || !showMinutes) && this._secondsPos.has(cursor)) ||
1920+
(!showHours && !showMinutes && this._secondsPos.has(cursor));
1921+
}
1922+
1923+
private cursorOnAmPm(cursor: number, showHours: boolean, showMinutes: boolean,
1924+
showSeconds: boolean, showAmPm: boolean): boolean {
1925+
return showAmPm &&
1926+
(showHours && showMinutes && showSeconds && this._amPmPos.has(cursor)) ||
1927+
((!showHours || !showMinutes || !showSeconds) && this._amPmPos.has(cursor)) ||
1928+
(!showHours && (!showMinutes || !showSeconds) && this._amPmPos.has(cursor));
1929+
}
1930+
1931+
private updateValidity() {
1932+
this._onTouchedCallback();
1933+
if (this._ngControl && !this._ngControl.valid) {
1934+
this._inputDirective.valid = IgxInputState.INVALID;
1935+
} else {
1936+
this._inputDirective.valid = IgxInputState.INITIAL;
1937+
}
1938+
}
19081939
}
19091940

19101941
/**

0 commit comments

Comments
 (0)