|
1 | | -import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core'; |
| 1 | +import { ChangeDetectorRef, Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; |
2 | 2 | import { UntypedFormControl } from '@angular/forms'; |
3 | 3 |
|
4 | 4 | import { |
@@ -66,7 +66,8 @@ import { DynamicDateControlValue } from '@ng-dynamic-forms/core/lib/model/dynami |
66 | 66 | styleUrls: ['./section-upload-file-edit.component.scss'], |
67 | 67 | templateUrl: './section-upload-file-edit.component.html', |
68 | 68 | }) |
69 | | -export class SubmissionSectionUploadFileEditComponent implements OnInit { |
| 69 | +export class SubmissionSectionUploadFileEditComponent |
| 70 | + implements OnInit, OnDestroy { |
70 | 71 |
|
71 | 72 | /** |
72 | 73 | * The FormComponent reference |
@@ -435,13 +436,31 @@ export class SubmissionSectionUploadFileEditComponent implements OnInit { |
435 | 436 | delete currentAccessCondition.startDate; |
436 | 437 | } else if (accessCondition.startDate) { |
437 | 438 | 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); |
439 | 449 | } |
440 | 450 | if (!accessConditionOpt.hasEndDate) { |
441 | 451 | delete currentAccessCondition.endDate; |
442 | 452 | } else if (accessCondition.endDate) { |
443 | 453 | 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); |
445 | 464 | } |
446 | 465 | accessConditionsToSave.push(currentAccessCondition); |
447 | 466 | } |
|
0 commit comments