Skip to content

Commit 274b880

Browse files
committed
fix(date-picker): stop input self validation, #6471
1 parent 8f2143d commit 274b880

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
@@ -380,6 +380,15 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
380380
return this._dropDownOverlaySettings || this._defaultDropDownOverlaySettings;
381381
}
382382

383+
public get required(): boolean {
384+
if (this._ngControl && this._ngControl.control && this._ngControl.control.validator) {
385+
// Run the validation with empty object to check if required is enabled.
386+
const error = this._ngControl.control.validator({} as AbstractControl);
387+
// this.inputGroup.isRequired = error && error.required;
388+
return error && error.required;
389+
}
390+
}
391+
383392
public set dropDownOverlaySettings(value: OverlaySettings) {
384393
this._dropDownOverlaySettings = value;
385394
}
@@ -934,8 +943,6 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
934943
if (this._ngControl) {
935944
this._statusChanges$ = this._ngControl.statusChanges.subscribe(this.onStatusChanged.bind(this));
936945
}
937-
938-
this.manageRequiredAsterisk();
939946
}
940947

941948
protected onStatusChanged() {
@@ -948,16 +955,6 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
948955
input.valid = this._ngControl.valid ? IgxInputState.INITIAL : IgxInputState.INVALID;
949956
}
950957
}
951-
this.manageRequiredAsterisk();
952-
}
953-
954-
protected manageRequiredAsterisk(): void {
955-
if (this._ngControl && this._ngControl.control.validator) {
956-
// Run the validation with empty object to check if required is enabled.
957-
const error = this._ngControl.control.validator({} as AbstractControl);
958-
this.inputGroup.isRequired = error && error.required;
959-
this._cdr.markForCheck();
960-
}
961958
}
962959

963960
/**
@@ -1422,7 +1419,7 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
14221419
return DatePickerUtil.addPromptCharsEditMode(this.dateFormatParts, this.value, changedValue);
14231420
}
14241421

1425-
private _updateValidity() {
1422+
public _updateValidity() {
14261423
this._onTouchedCallback();
14271424
const input = this.readonlyInputDirective || this.editableInputDirective || this.input;
14281425
if (input && this._ngControl && !this._ngControl.valid) {

0 commit comments

Comments
 (0)