From 5c5bd4b6424cb38fd8e13e5a602227a3bb6069c2 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 10 Dec 2020 15:44:17 +0100 Subject: [PATCH] Fix dateRange cell --- .../date-range-cell/date-range-cell.component.html | 4 ++-- .../date-range-cell/date-range-cell.component.ts | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) 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; + } }