|
1 | 1 | import { SectionAccessesService } from './section-accesses.service'; |
2 | 2 | import { Component, Inject, ViewChild } from '@angular/core'; |
| 3 | +import { FormControl } from '@angular/forms'; |
3 | 4 |
|
4 | 5 | import { filter, map, mergeMap, take } from 'rxjs/operators'; |
5 | 6 | import { combineLatest, Observable, of, Subscription } from 'rxjs'; |
@@ -176,6 +177,20 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent { |
176 | 177 | const value = this.formOperationsService.getFieldValueFromChangeEvent(event); |
177 | 178 | this.operationsBuilder.replace(this.pathCombiner.getPath(path), value.value, true); |
178 | 179 | } 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 | + |
179 | 194 | // validate form |
180 | 195 | this.formService.validateAllFormFields(this.formRef.formGroup); |
181 | 196 | this.formService.isValid(this.formId).pipe( |
@@ -360,4 +375,5 @@ export class SubmissionSectionAccessesComponent extends SectionModelComponent { |
360 | 375 | const temp = Array.isArray(field) ? field[0] : field; |
361 | 376 | return (temp) ? temp.value : undefined; |
362 | 377 | } |
| 378 | + |
363 | 379 | } |
0 commit comments