import { FormArray, FormControl, UntypedFormArray, UntypedFormBuilder, UntypedFormGroup, Validators } from "@angular/forms"; import { DmpAccessType } from "@app/core/common/enum/dmp-access-type"; import { DmpContactType } from "@app/core/common/enum/dmp-contact-type"; import { DmpStatus } from "@app/core/common/enum/dmp-status"; import { DmpUserRole } from "@app/core/common/enum/dmp-user-role"; import { DmpUserType } from "@app/core/common/enum/dmp-user-type"; import { IsActive } from "@app/core/common/enum/is-active.enum"; import { DmpBlueprint } from "@app/core/model/dmp-blueprint/dmp-blueprint"; import { Dmp, DmpBlueprintValue, DmpBlueprintValuePersist, DmpContact, DmpContactPersist, DmpDescriptionTemplate, DmpDescriptionTemplatePersist, DmpPersist, DmpProperties, DmpPropertiesPersist, DmpReferenceDataPersist, DmpReferencePersist, DmpUser, DmpUserPersist } from "@app/core/model/dmp/dmp"; import { DmpReference } from "@app/core/model/dmp/dmp-reference"; import { ReferencePersist } from "@app/core/model/reference/reference"; import { BaseEditorModel } from "@common/base/base-form-editor-model"; import { BackendErrorValidator } from '@common/forms/validation/custom-validator'; import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; import { Validation, ValidationContext } from '@common/forms/validation/validation-context'; import { Guid } from "@common/types/guid"; export class DmpEditorModel extends BaseEditorModel implements DmpPersist { label: string; status: DmpStatus; properties: DmpPropertiesEditorModel = new DmpPropertiesEditorModel(this.validationErrorModel); description: String; language: String; blueprint: Guid; accessType: DmpAccessType; descriptionTemplates: DmpDescriptionTemplateEditorModel[] = []; users: DmpUserEditorModel[] = []; permissions: string[]; public validationErrorModel: ValidationErrorModel = new ValidationErrorModel(); protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); constructor() { super(); } public fromModel(item: Dmp): DmpEditorModel { if (item) { super.fromModel(item); this.label = item.label; this.status = item.status; this.properties = new DmpPropertiesEditorModel(this.validationErrorModel).fromModel(item.properties, item.dmpReferences?.filter(x => x.isActive === IsActive.Active), item.blueprint); this.description = item.description; this.language = item.language; this.blueprint = item.blueprint?.id; this.accessType = item.accessType; if (item?.dmpUsers) { item.dmpUsers.filter(x => x.isActive === IsActive.Active).map(x => this.users.push(new DmpUserEditorModel(this.validationErrorModel).fromModel(x))); } item.blueprint.definition.sections.forEach(section => { if (section.hasTemplates) { const sectionTempaltesFromDmp = item.dmpDescriptionTemplates?.filter(x => x.sectionId == section.id) || []; if (sectionTempaltesFromDmp.length > 0) { item.dmpDescriptionTemplates?.filter(x => x.sectionId == section.id).forEach(dmpDescriptionTemplate => { this.descriptionTemplates.push(new DmpDescriptionTemplateEditorModel(this.validationErrorModel).fromModel( { sectionId: section.id, descriptionTemplateGroupId: dmpDescriptionTemplate?.descriptionTemplateGroupId, })); }); } else if (section.descriptionTemplates?.length > 0) { section.descriptionTemplates.forEach(blueprintDefinedDescriptionTemplate => { this.descriptionTemplates.push(new DmpDescriptionTemplateEditorModel(this.validationErrorModel).fromModel( { sectionId: section.id, descriptionTemplateGroupId: blueprintDefinedDescriptionTemplate?.descriptionTemplateGroupId, })); }); } else { this.descriptionTemplates.push(new DmpDescriptionTemplateEditorModel(this.validationErrorModel).fromModel( { sectionId: section.id, })); } } }); } return this; } buildForm(context: ValidationContext = null, disabled: boolean = false): UntypedFormGroup { if (context == null) { context = this.createValidationContext(); } const formGroup = this.formBuilder.group({ id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators], label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators], status: [{ value: this.status, disabled: disabled }, context.getValidation('status').validators], properties: this.properties.buildForm({ rootPath: `properties.` }), users: this.formBuilder.array( (this.users ?? []).map( (item, index) => item.buildForm({ rootPath: `users[${index}].` }) ), context.getValidation('users').validators ), description: [{ value: this.description, disabled: disabled }, context.getValidation('description').validators], language: [{ value: this.language, disabled: disabled }, context.getValidation('language').validators], blueprint: [{ value: this.blueprint, disabled: disabled }, context.getValidation('blueprint').validators], accessType: [{ value: this.accessType, disabled: disabled }, context.getValidation('accessType').validators], hash: [{ value: this.hash, disabled: disabled }, context.getValidation('hash').validators] }); const descriptionTemplatesFormGroup = this.formBuilder.group({}); (this.descriptionTemplates ?? []).filter(x => x?.sectionId).map(x => x.sectionId).map( (item, index) => descriptionTemplatesFormGroup.addControl(item.toString(), new FormControl(this.descriptionTemplates?.filter(x => x.sectionId === item)?.filter(x => x.descriptionTemplateGroupId).map(x => x.descriptionTemplateGroupId) || [], context.getValidation('descriptionTemplates').validators)) ); // // buildForm({ // // rootPath: `descriptionTemplates[${index}].` // })), //context.getValidation('descriptionTemplates') // )) formGroup.addControl('descriptionTemplates', descriptionTemplatesFormGroup); return formGroup; } createValidationContext(): ValidationContext { const baseContext: ValidationContext = new ValidationContext(); const baseValidationArray: Validation[] = new Array(); baseValidationArray.push({ key: 'id', validators: [BackendErrorValidator(this.validationErrorModel, 'id')] }); baseValidationArray.push({ key: 'label', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'label')] }); baseValidationArray.push({ key: 'status', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'status')] }); baseValidationArray.push({ key: 'properties', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'properties')] }); baseValidationArray.push({ key: 'description', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'description')] }); baseValidationArray.push({ key: 'language', validators: [BackendErrorValidator(this.validationErrorModel, 'language')] }); baseValidationArray.push({ key: 'blueprint', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'blueprint')] }); baseValidationArray.push({ key: 'accessType', validators: [BackendErrorValidator(this.validationErrorModel, 'accessType')] }); baseValidationArray.push({ key: 'descriptionTemplates', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'descriptionTemplates')] }); baseValidationArray.push({ key: 'users', validators: [BackendErrorValidator(this.validationErrorModel, `users`)] }); baseValidationArray.push({ key: 'hash', validators: [] }); baseContext.validation = baseValidationArray; return baseContext; } createChildContact(index: number): UntypedFormGroup { const contact: DmpContactEditorModel = new DmpContactEditorModel(this.validationErrorModel); return contact.buildForm({ rootPath: 'properties.contacts[' + index + '].' }); } static reApplyPropertiesValidators(params: { formGroup: UntypedFormGroup, validationErrorModel: ValidationErrorModel, }): void { const { formGroup, validationErrorModel } = params; const control = formGroup?.get('properties'); DmpPropertiesEditorModel.reapplyValidators({ formGroup: control as UntypedFormGroup, rootPath: `properties.`, validationErrorModel: validationErrorModel }); const descriptionTemplates = formGroup?.get('descriptionTemplates') as UntypedFormGroup; const keys = Object.keys(descriptionTemplates.value as Object); keys.forEach((key) => { const control = descriptionTemplates?.get(key); DmpBlueprintValueEditorModel.reapplyValidators({ formGroup: control as UntypedFormGroup, rootPath: `descriptionTemplates[${key}].`, validationErrorModel: validationErrorModel }) }); (formGroup.get('users') as FormArray).controls?.forEach( (control, index) => DmpUserEditorModel.reapplyValidators({ formGroup: control as UntypedFormGroup, rootPath: `users[${index}].`, validationErrorModel: validationErrorModel }) ); } } export class DmpPropertiesEditorModel implements DmpPropertiesPersist { dmpBlueprintValues: Map = new Map; contacts: DmpContactEditorModel[] = []; protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); constructor( public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() ) { } fromModel(item: DmpProperties, dmpReferences: DmpReference[], dmpBlueprint: DmpBlueprint): DmpPropertiesEditorModel { dmpBlueprint.definition.sections.forEach(section => { section.fields?.forEach(field => { this.dmpBlueprintValues.set(field.id, new DmpBlueprintValueEditorModel(this.validationErrorModel).fromModel( { fieldId: field.id, fieldValue: item?.dmpBlueprintValues?.find(x => x.fieldId == field.id)?.fieldValue, }, dmpReferences)); }); }); if (item?.contacts) { item.contacts.map(x => this.contacts.push(new DmpContactEditorModel(this.validationErrorModel).fromModel(x))); } return this; } buildForm(params?: { context?: ValidationContext, disabled?: boolean, rootPath?: string }, dmpReferences?: DmpReference[], dmpBlueprint?: DmpBlueprint): UntypedFormGroup { let { context = null, disabled = false, rootPath } = params ?? {} if (context == null) { context = DmpPropertiesEditorModel.createValidationContext({ validationErrorModel: this.validationErrorModel, rootPath }); } const formGroup = this.formBuilder.group({ contacts: this.formBuilder.array( (this.contacts ?? []).map( (item, index) => item.buildForm({ rootPath: `${rootPath}contacts[${index}].` }) ), context.getValidation('contacts').validators ), }); const dmpBlueprintValuesFormGroup = this.formBuilder.group({}); this.dmpBlueprintValues.forEach((value, key) => dmpBlueprintValuesFormGroup.addControl(key.toString(), value.buildForm({ rootPath: `${rootPath}dmpBlueprintValues[${key}].` })), context.getValidation('dmpBlueprintValues') ) formGroup.addControl('dmpBlueprintValues', dmpBlueprintValuesFormGroup); return formGroup; } static createValidationContext(params: { rootPath?: string, validationErrorModel: ValidationErrorModel }): ValidationContext { const { rootPath = '', validationErrorModel } = params; const baseContext: ValidationContext = new ValidationContext(); const baseValidationArray: Validation[] = new Array(); baseValidationArray.push({ key: 'dmpBlueprintValues', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}dmpBlueprintValues`)] }); baseValidationArray.push({ key: 'contacts', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}contacts`)] }); baseContext.validation = baseValidationArray; return baseContext; } static reapplyValidators(params: { formGroup: UntypedFormGroup, validationErrorModel: ValidationErrorModel, rootPath: string }): void { const { formGroup, rootPath, validationErrorModel } = params; const dmpBlueprintValues = formGroup?.get('dmpBlueprintValues') as UntypedFormGroup; const keys = Object.keys(dmpBlueprintValues.value as Object); keys.forEach((key) => { const control = dmpBlueprintValues?.get(key); DmpBlueprintValueEditorModel.reapplyValidators({ formGroup: control as UntypedFormGroup, rootPath: `${rootPath}dmpBlueprintValues[${key}].`, validationErrorModel: validationErrorModel }) }); (formGroup.get('contacts') as FormArray).controls?.forEach( (control, index) => DmpContactEditorModel.reapplyValidators({ formGroup: control as UntypedFormGroup, rootPath: `${rootPath}contacts[${index}].`, validationErrorModel: validationErrorModel }) ); } } export class DmpBlueprintValueEditorModel implements DmpBlueprintValuePersist { fieldId: Guid; fieldValue: string; references: DmpReferencePersist[] = []; protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); constructor( public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() ) { } fromModel(item: DmpBlueprintValue, dmpReferences: DmpReference[]): DmpBlueprintValueEditorModel { this.fieldId = item.fieldId; this.fieldValue = item.fieldValue; // TODO check typeId field if(dmpReferences){ dmpReferences.forEach(dmpReference => { if(dmpReference.data.blueprintFieldId == this.fieldId){ this.references.push({ data: dmpReference.data, reference: { id: dmpReference.reference.id, label: dmpReference.reference.label, reference: dmpReference.reference.reference, source: dmpReference.reference.source, typeId: null, description: dmpReference.reference.source, definition: dmpReference.reference.definition, abbreviation: dmpReference.reference.abbreviation, sourceType: dmpReference.reference.sourceType } }) } }) } return this; } buildForm(params?: { context?: ValidationContext, disabled?: boolean, rootPath?: string }): UntypedFormGroup { let { context = null, disabled = false, rootPath } = params ?? {} if (context == null) { context = DmpBlueprintValueEditorModel.createValidationContext({ validationErrorModel: this.validationErrorModel, rootPath }); } return this.formBuilder.group({ fieldId: [{ value: this.fieldId, disabled: disabled }, context.getValidation('fieldId').validators], fieldValue: [{ value: this.fieldValue, disabled: disabled }, context.getValidation('fieldValue').validators], references: [{ value: this.references?.map(x => x.reference), disabled: disabled }, context.getValidation('references').validators], }); } static createValidationContext(params: { rootPath?: string, validationErrorModel: ValidationErrorModel }): ValidationContext { const { rootPath = '', validationErrorModel } = params; const baseContext: ValidationContext = new ValidationContext(); const baseValidationArray: Validation[] = new Array(); baseValidationArray.push({ key: 'fieldId', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}fieldId`)] }); baseValidationArray.push({ key: 'fieldValue', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}fieldValue`)] }); baseValidationArray.push({ key: 'references', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}references`)] }); baseContext.validation = baseValidationArray; return baseContext; } static reapplyValidators(params: { formGroup: UntypedFormGroup, validationErrorModel: ValidationErrorModel, rootPath: string }): void { const { formGroup, rootPath, validationErrorModel } = params; const context = DmpBlueprintValueEditorModel.createValidationContext({ rootPath, validationErrorModel }); ['fieldId', 'fieldValue', 'references'].forEach(keyField => { const control = formGroup?.get(keyField); control?.clearValidators(); control?.addValidators(context.getValidation(keyField).validators); }) } } export class DmpContactEditorModel implements DmpContactPersist { userId: Guid; firstName: string; lastName: string; email: string; contactType: DmpContactType= DmpContactType.Internal; protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); constructor( public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() ) { } fromModel(item: DmpContact): DmpContactEditorModel { if(item?.user?.id) this.userId = item.user.id; this.firstName = item.firstName; this.lastName = item.lastName; this.email = item.email; this.contactType = (item == null || this.userId != null) ? DmpContactType.Internal : DmpContactType.External; return this; } buildForm(params?: { context?: ValidationContext, disabled?: boolean, rootPath?: string }): UntypedFormGroup { let { context = null, disabled = false, rootPath } = params ?? {} if (context == null) { context = DmpContactEditorModel.createValidationContext({ validationErrorModel: this.validationErrorModel, rootPath }); } return this.formBuilder.group({ userId: [{ value: this.userId, disabled: disabled }, context.getValidation('userId').validators], firstName: [{ value: this.firstName, disabled: disabled }, context.getValidation('firstName').validators], lastName: [{ value: this.lastName, disabled: disabled }, context.getValidation('lastName').validators], email: [{ value: this.email, disabled: disabled }, context.getValidation('email').validators], contactType: [{ value: this.contactType, disabled: disabled }, context.getValidation('contactType').validators], }); } static createValidationContext(params: { rootPath?: string, validationErrorModel: ValidationErrorModel }): ValidationContext { const { rootPath = '', validationErrorModel } = params; const baseContext: ValidationContext = new ValidationContext(); const baseValidationArray: Validation[] = new Array(); baseValidationArray.push({ key: 'userId', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}userId`)] }); baseValidationArray.push({ key: 'firstName', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}firstName`)] }); baseValidationArray.push({ key: 'lastName', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}lastName`)] }); baseValidationArray.push({ key: 'email', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}email`)] }); baseValidationArray.push({ key: 'contactType', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}contactType`)] }); baseContext.validation = baseValidationArray; return baseContext; } static reapplyValidators(params: { formGroup: UntypedFormGroup, validationErrorModel: ValidationErrorModel, rootPath: string }): void { const { formGroup, rootPath, validationErrorModel } = params; const context = DmpContactEditorModel.createValidationContext({ rootPath, validationErrorModel }); ['userId', 'firstName', 'lastName', 'email'].forEach(keyField => { const control = formGroup?.get(keyField); control?.clearValidators(); control?.addValidators(context.getValidation(keyField).validators); }) } } export class DmpUserEditorModel implements DmpUserPersist { user: Guid; role: DmpUserRole; email: string; userType: DmpUserType= DmpUserType.Internal; sectionId: Guid; protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); constructor( public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() ) { } fromModel(item: DmpUser): DmpUserEditorModel { if(item?.user?.id) this.user = item.user.id; this.role = item.role; // TODO this.email = item.email; this.userType = (item == null || this.user != null) ? DmpUserType.Internal : DmpUserType.External; this.sectionId = item.sectionId; return this; } buildForm(params?: { context?: ValidationContext, disabled?: boolean, rootPath?: string }): UntypedFormGroup { let { context = null, disabled = false, rootPath } = params ?? {} if (context == null) { context = DmpUserEditorModel.createValidationContext({ validationErrorModel: this.validationErrorModel, rootPath }); } return this.formBuilder.group({ user: [{ value: this.user, disabled: disabled }, context.getValidation('user').validators], role: [{ value: this.role, disabled: disabled }, context.getValidation('role').validators], email: [{ value: this.email, disabled: disabled }, context.getValidation('email').validators], sectionId: [{ value: this.sectionId, disabled: disabled }, context.getValidation('sectionId').validators], userType: [{ value: this.userType, disabled: disabled }, context.getValidation('userType').validators], }); } static createValidationContext(params: { rootPath?: string, validationErrorModel: ValidationErrorModel }): ValidationContext { const { rootPath = '', validationErrorModel } = params; const baseContext: ValidationContext = new ValidationContext(); const baseValidationArray: Validation[] = new Array(); baseValidationArray.push({ key: 'user', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}user`)] }); baseValidationArray.push({ key: 'role', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}role`)] }); baseValidationArray.push({ key: 'email', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}email`)] }); baseValidationArray.push({ key: 'sectionId', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}sectionId`)] }); baseValidationArray.push({ key: 'userType', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}userType`)] }); baseContext.validation = baseValidationArray; return baseContext; } static reapplyValidators(params: { formGroup: UntypedFormGroup, validationErrorModel: ValidationErrorModel, rootPath: string }): void { const { formGroup, rootPath, validationErrorModel } = params; const context = DmpUserEditorModel.createValidationContext({ rootPath, validationErrorModel }); ['user', 'role', 'email', 'sectionId'].forEach(keyField => { const control = formGroup?.get(keyField); control?.clearValidators(); control?.addValidators(context.getValidation(keyField).validators); }) } } export class DmpReferenceEditorModel implements DmpReferencePersist { id: Guid; reference: ReferencePersist; referenceId: Guid; data: DmpReferenceDataPersist; hash: string; protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); constructor( public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() ) { } fromModel(item: DmpReference): DmpReferenceEditorModel { this.id = item.id; // this.reference = item.reference; //TODO: refactor reference type this.data = item.data; this.hash = item.hash; return this; } buildForm(params?: { context?: ValidationContext, disabled?: boolean, rootPath?: string }): UntypedFormGroup { let { context = null, disabled = false, rootPath } = params ?? {} if (context == null) { context = DmpReferenceEditorModel.createValidationContext({ validationErrorModel: this.validationErrorModel, rootPath }); } return this.formBuilder.group({ id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators], reference: [{ value: this.reference, disabled: disabled }, context.getValidation('reference').validators], data: [{ value: this.data, disabled: disabled }, context.getValidation('data').validators], hash: [{ value: this.hash, disabled: disabled }, context.getValidation('hash').validators] }); } static createValidationContext(params: { rootPath?: string, validationErrorModel: ValidationErrorModel }): ValidationContext { const { rootPath = '', validationErrorModel } = params; const baseContext: ValidationContext = new ValidationContext(); const baseValidationArray: Validation[] = new Array(); baseValidationArray.push({ key: 'id', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}id`)] }); baseValidationArray.push({ key: 'reference', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}reference`)] }); baseValidationArray.push({ key: 'data', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}data`)] }); baseValidationArray.push({ key: 'hash', validators: [] }); baseContext.validation = baseValidationArray; return baseContext; } } export class DmpDescriptionTemplateEditorModel implements DmpDescriptionTemplatePersist { descriptionTemplateGroupId: Guid; sectionId: Guid; protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); constructor( public validationErrorModel: ValidationErrorModel = new ValidationErrorModel() ) { } fromModel(item: DmpDescriptionTemplate): DmpDescriptionTemplateEditorModel { this.descriptionTemplateGroupId = item.descriptionTemplateGroupId; this.sectionId = item.sectionId; return this; } buildForm(params?: { context?: ValidationContext, disabled?: boolean, rootPath?: string }): UntypedFormGroup { let { context = null, disabled = false, rootPath } = params ?? {} if (context == null) { context = DmpDescriptionTemplateEditorModel.createValidationContext({ validationErrorModel: this.validationErrorModel, rootPath }); } return this.formBuilder.group({ descriptionTemplateGroupId: [{ value: this.descriptionTemplateGroupId, disabled: disabled }, context.getValidation('descriptionTemplateGroupId').validators], sectionId: [{ value: this.sectionId, disabled: disabled }, context.getValidation('sectionId').validators], }); } static createValidationContext(params: { rootPath?: string, validationErrorModel: ValidationErrorModel }): ValidationContext { const { rootPath = '', validationErrorModel } = params; const baseContext: ValidationContext = new ValidationContext(); const baseValidationArray: Validation[] = new Array(); baseValidationArray.push({ key: 'descriptionTemplateGroupId', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}descriptionTemplateGroupId`)] }); baseValidationArray.push({ key: 'sectionId', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}sectionId`)] }); baseContext.validation = baseValidationArray; return baseContext; } static reapplyValidators(params: { formGroup: UntypedFormGroup, validationErrorModel: ValidationErrorModel, rootPath: string }): void { const { formGroup, rootPath, validationErrorModel } = params; const context = DmpDescriptionTemplateEditorModel.createValidationContext({ rootPath, validationErrorModel }); ['descriptionTemplateGroupId', 'sectionId'].forEach(keyField => { const control = formGroup?.get(keyField); control?.clearValidators(); control?.addValidators(context.getValidation(keyField).validators); }) } }