Skip to content

Commit 626def8

Browse files
committed
fix(date-picker): stop input self validation, #6471
1 parent d97a541 commit 626def8

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
[disabled]="disabled"
1212
(blur)="onBlur($event)"
1313
readonly
14+
required="required"
15+
[shouldCheckValidity]="false"
1416
/>
1517
</igx-input-group>
1618
</ng-template>
@@ -36,6 +38,8 @@
3638
(wheel)="onWheel($event)"
3739
(input)="onInput($event)"
3840
(focus)="onFocus()"
41+
required="required"
42+
[shouldCheckValidity]="false"
3943
/>
4044
<igx-suffix *ngIf="!isEmpty" (click)="clear()">
4145
<igx-icon>clear</igx-icon>

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

+10-13
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,15 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
336336
return this._dropDownOverlaySettings || this._defaultDropDownOverlaySettings;
337337
}
338338

339+
public get required(): boolean {
340+
if (this._ngControl && this._ngControl.control && this._ngControl.control.validator) {
341+
// Run the validation with empty object to check if required is enabled.
342+
const error = this._ngControl.control.validator({} as AbstractControl);
343+
// this.inputGroup.isRequired = error && error.required;
344+
return error && error.required;
345+
}
346+
}
347+
339348
public set dropDownOverlaySettings(value: OverlaySettings) {
340349
this._dropDownOverlaySettings = value;
341350
}
@@ -884,8 +893,6 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
884893
if (this._ngControl) {
885894
this._statusChanges$ = this._ngControl.statusChanges.subscribe(this.onStatusChanged.bind(this));
886895
}
887-
888-
this.manageRequiredAsterisk();
889896
}
890897

891898
protected onStatusChanged() {
@@ -898,16 +905,6 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
898905
input.valid = this._ngControl.valid ? IgxInputState.INITIAL : IgxInputState.INVALID;
899906
}
900907
}
901-
this.manageRequiredAsterisk();
902-
}
903-
904-
protected manageRequiredAsterisk(): void {
905-
if (this._ngControl && this._ngControl.control.validator) {
906-
// Run the validation with empty object to check if required is enabled.
907-
const error = this._ngControl.control.validator({} as AbstractControl);
908-
this.inputGroup.isRequired = error && error.required;
909-
this._cdr.markForCheck();
910-
}
911908
}
912909

913910
/**
@@ -1332,7 +1329,7 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
13321329
return DatePickerUtil.addPromptCharsEditMode(this.dateFormatParts, this.value, changedValue);
13331330
}
13341331

1335-
private _updateValidity() {
1332+
public _updateValidity() {
13361333
this._onTouchedCallback();
13371334
const input = this.readonlyInputDirective || this.editableInputDirective || this.input;
13381335
if (input && this._ngControl && !this._ngControl.valid) {

0 commit comments

Comments
 (0)