Open alexschilpp opened 2 years ago
Thanks for filing the issue - can you provide a working reproduction?
Sorry, this one should work: https://stackblitz.com/edit/angular-ivy-a3ezpw?file=src/app/app.component.html
I also getting similar issue with MatDateRange, when entering the date manually,
Showing an Invalid date.
Steps to reproduce:
This bug is related to: 21875
You can use this Workaround (Directive):
@Directive({
selector: 'mat-date-range-input [sharedInputFix]'
})
export class SharedMatDateRangeInputFixDirective extends DestroyEmitterDirective() implements AfterContentInit, OnDestroy {
@ContentChild(MatStartDate, { read: FormControlDirective })
startDateControlDirective: FormControlDirective
@ContentChild(MatEndDate, { read: FormControlDirective })
endDateControlDirective: FormControlDirective
ngAfterContentInit(): void {
this.startDateControlDirective.valueChanges.pipe(distinctUntilChanged(), takeUntil(this.destroyed$)).subscribe(() =>
setTimeout(() => {
this.endDateControlDirective.control.updateValueAndValidity({
emitEvent: true,
onlySelf: false
})
})
)
this.endDateControlDirective.valueChanges.pipe(distinctUntilChanged(), takeUntil(this.destroyed$)).subscribe(() =>
setTimeout(() => {
this.startDateControlDirective.control.updateValueAndValidity({
emitEvent: true,
onlySelf: false
})
})
)
}
}
The setTimeout(...) is important... unfortunately.
Is this a regression?
The previous version in which this bug was not present was
No response
Description
When manually entering the start date to a date after the end date, you get a validation error "Invalid start date" which is correct and expected. However, if you correct the end date to a date that is after the start date the validation doesn't seem to update and still shows "Invalid start date".
Reproduction
https://stackblitz.com/run?file=src/app/date-range-picker-forms-example.tshttps://stackblitz.com/edit/angular-ivy-a3ezpw?file=src/app/app.component.htmlSteps to reproduce:
Expected Behavior
As soon as the end date is set to after the start date, validation should update and hide the error.
Actual Behavior
"invalid start date" error is still shown.
Environment