Skip to content

Commit 1e7ede0

Browse files
committed
Don't allow the date picker to exceed the maximum start or end date for an access option.
1 parent 1d58910 commit 1e7ede0

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

src/app/submission/sections/upload/file/edit/section-upload-file-edit.component.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
1+
import { ChangeDetectorRef, Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
22
import { FormControl } from '@angular/forms';
33

44
import {
@@ -66,7 +66,8 @@ import { DynamicDateControlValue } from '@ng-dynamic-forms/core/lib/model/dynami
6666
styleUrls: ['./section-upload-file-edit.component.scss'],
6767
templateUrl: './section-upload-file-edit.component.html',
6868
})
69-
export class SubmissionSectionUploadFileEditComponent implements OnInit {
69+
export class SubmissionSectionUploadFileEditComponent
70+
implements OnInit, OnDestroy {
7071

7172
/**
7273
* The FormComponent reference
@@ -435,13 +436,31 @@ export class SubmissionSectionUploadFileEditComponent implements OnInit {
435436
delete currentAccessCondition.startDate;
436437
} else if (accessCondition.startDate) {
437438
const startDate = this.retrieveValueFromField(accessCondition.startDate);
438-
currentAccessCondition.startDate = dateToISOFormat(startDate);
439+
// Clamp the start date to the maximum, if any, since the
440+
// datepicker sometimes exceeds it.
441+
let startDateDate = new Date(startDate);
442+
if (accessConditionOpt.maxStartDate) {
443+
const maxStartDateDate = new Date(accessConditionOpt.maxStartDate);
444+
if (startDateDate > maxStartDateDate) {
445+
startDateDate = maxStartDateDate;
446+
}
447+
}
448+
currentAccessCondition.startDate = dateToISOFormat(startDateDate);
439449
}
440450
if (!accessConditionOpt.hasEndDate) {
441451
delete currentAccessCondition.endDate;
442452
} else if (accessCondition.endDate) {
443453
const endDate = this.retrieveValueFromField(accessCondition.endDate);
444-
currentAccessCondition.endDate = dateToISOFormat(endDate);
454+
// Clamp the end date to the maximum, if any, since the
455+
// datepicker sometimes exceeds it.
456+
let endDateDate = new Date(endDate);
457+
if (accessConditionOpt.maxEndDate) {
458+
const maxEndDateDate = new Date(accessConditionOpt.maxEndDate);
459+
if (endDateDate > maxEndDateDate) {
460+
endDateDate = maxEndDateDate;
461+
}
462+
}
463+
currentAccessCondition.endDate = dateToISOFormat(endDateDate);
445464
}
446465
accessConditionsToSave.push(currentAccessCondition);
447466
}

0 commit comments

Comments
 (0)