Add search input date check
This commit is contained in:
parent
615727e09d
commit
587e231e05
@ -3,11 +3,11 @@
|
|||||||
<h2>When is your trip?</h2>
|
<h2>When is your trip?</h2>
|
||||||
<mat-form-field appearance="outline">
|
<mat-form-field appearance="outline">
|
||||||
<mat-label>Start</mat-label>
|
<mat-label>Start</mat-label>
|
||||||
<input [(ngModel)]="from" matInput required type="date">
|
<input (change)="checkDates()" [(ngModel)]="from" [min]="today" matInput required type="date">
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-form-field appearance="outline">
|
<mat-form-field appearance="outline">
|
||||||
<mat-label>End</mat-label>
|
<mat-label>End</mat-label>
|
||||||
<input [(ngModel)]="to" matInput required type="date">
|
<input (change)="checkDates()" [(ngModel)]="to" [min]="from" matInput required type="date">
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@ -24,6 +24,8 @@ export class SearchInputComponent implements OnInit {
|
|||||||
singlePresetSelection = {};
|
singlePresetSelection = {};
|
||||||
multiPresetSelection = {};
|
multiPresetSelection = {};
|
||||||
|
|
||||||
|
readonly today = this.from = formatDate(new Date(), 'yyyy-MM-dd', 'en-GB');
|
||||||
|
|
||||||
constructor(private router: Router, private ps: PresetService, private ss: SearchService) {
|
constructor(private router: Router, private ps: PresetService, private ss: SearchService) {
|
||||||
const from = new Date();
|
const from = new Date();
|
||||||
const to = new Date();
|
const to = new Date();
|
||||||
@ -94,4 +96,15 @@ export class SearchInputComponent implements OnInit {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkDates() {
|
||||||
|
const fromDate = new Date(this.from);
|
||||||
|
const toDate = new Date(this.to);
|
||||||
|
|
||||||
|
if (toDate <= fromDate) {
|
||||||
|
const newToDate = new Date(this.from);
|
||||||
|
newToDate.setDate(fromDate.getDate() + 1);
|
||||||
|
this.to = formatDate(newToDate, 'yyyy-MM-dd', 'en-GB');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user