Skip to content

Commit 4e5bf6e

Browse files
committed
[CST-4506] Clean date fields when switching through access conditions
1 parent f991b4e commit 4e5bf6e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/app/submission/sections/accesses/section-accesses.component.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { SectionAccessesService } from './section-accesses.service';
22
import { Component, Inject, ViewChild } from '@angular/core';
3+
import { FormControl } from '@angular/forms';
34

45
import { filter, map, mergeMap, take } from 'rxjs/operators';
56
import { combineLatest, Observable, of, Subscription } from 'rxjs';
@@ -176,6 +177,20 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
176177
const value = this.formOperationsService.getFieldValueFromChangeEvent(event);
177178
this.operationsBuilder.replace(this.pathCombiner.getPath(path), value.value, true);
178179
} else {
180+
if (event.model.id === FORM_ACCESS_CONDITION_TYPE_CONFIG.id) {
181+
// Clear previous state when switching through different access conditions
182+
183+
const startDateControl: FormControl = event.control.parent.get('startDate') as FormControl;
184+
const endDateControl: FormControl = event.control.parent.get('endDate') as FormControl;
185+
186+
startDateControl?.markAsUntouched();
187+
endDateControl?.markAsUntouched();
188+
189+
startDateControl?.setValue(null);
190+
endDateControl?.setValue(null);
191+
event.control.parent.markAsDirty();
192+
}
193+
179194
// validate form
180195
this.formService.validateAllFormFields(this.formRef.formGroup);
181196
this.formService.isValid(this.formId).pipe(
@@ -360,4 +375,5 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent {
360375
const temp = Array.isArray(field) ? field[0] : field;
361376
return (temp) ? temp.value : undefined;
362377
}
378+
363379
}

0 commit comments

Comments
 (0)