diff --git a/src/app/components/tableComponents/date-range-cell/date-range-cell.component.html b/src/app/components/tableComponents/date-range-cell/date-range-cell.component.html index 15ad373..d43384c 100644 --- a/src/app/components/tableComponents/date-range-cell/date-range-cell.component.html +++ b/src/app/components/tableComponents/date-range-cell/date-range-cell.component.html @@ -9,7 +9,7 @@ matInput placeholder="Startdatum" [matDatepicker]="fromPicker" - [value]="from" + [value]="stringToDate(from)" disabled formControlName="from" (dateChange)="startDateChange($event)" @@ -33,7 +33,7 @@ matInput placeholder="Enddatum" [matDatepicker]="toPicker" - [value]="to" + [value]="stringToDate(to)" disabled formControlName="to" (dateChange)="endDateChange($event)" diff --git a/src/app/components/tableComponents/date-range-cell/date-range-cell.component.ts b/src/app/components/tableComponents/date-range-cell/date-range-cell.component.ts index 273570d..d8be64b 100644 --- a/src/app/components/tableComponents/date-range-cell/date-range-cell.component.ts +++ b/src/app/components/tableComponents/date-range-cell/date-range-cell.component.ts @@ -47,7 +47,7 @@ export class DateRangeCellComponent implements OnInit { this.dateRangeGroup.controls['to'].markAsTouched(); if (this.editable) { - setTimeout(()=>this.checkIfDateRangeIsValid()); + setTimeout(() => this.checkIfDateRangeIsValid()); } } @@ -64,11 +64,11 @@ export class DateRangeCellComponent implements OnInit { } checkIfDateRangeIsValid() { - if (this.required && this.from == null) { + if (this.required && !this.from) { this.setRangeError(true); return; } - if (this.to == null || this.from == null) { + if (!this.to || !this.from) { this.setRangeError(false); return; } @@ -97,4 +97,9 @@ export class DateRangeCellComponent implements OnInit { } return new Date(date).toLocaleDateString(); } + + stringToDate(dateString: string): Date { + if (!dateString) return null; + return new Date(dateString) || null; + } }