From 0e61925f8dddfe9933db496a3baf5a9ba452a8e3 Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Mon, 15 Jan 2024 13:33:49 +0200 Subject: [PATCH] validators remove logic --- .../editor/reference-type-editor.component.ts | 9 ++++ .../editor/reference-type-editor.model.ts | 49 ++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts index ba8a9fc32..6594a1e2e 100644 --- a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts +++ b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts @@ -227,6 +227,15 @@ export class ReferenceTypeEditorComponent extends BaseEditor ReferenceTypeFieldEditorModel.reapplyValidators({ + formGroup: control as UntypedFormGroup, + rootPath: `${rootPath}fields[${index}].`, + validationErrorModel: validationErrorModel + }) + ); + } + } export class ReferenceTypeFieldEditorModel implements ReferenceTypeFieldPersist { @@ -195,6 +224,24 @@ export class ReferenceTypeFieldEditorModel implements ReferenceTypeFieldPersist return baseContext; } + static reapplyValidators(params: { + formGroup: UntypedFormGroup, + validationErrorModel: ValidationErrorModel, + rootPath: string + }): void { + + const { formGroup, rootPath, validationErrorModel } = params; + const context = ReferenceTypeFieldEditorModel.createValidationContext({ + rootPath, + validationErrorModel + }); + + ['code', 'label', 'description', 'dataType'].forEach(keyField => { + const control = formGroup?.get(keyField); + control?.clearValidators(); + control?.addValidators(context.getValidation(keyField).validators); + }) + } } export class ReferenceTypeSourceBaseConfigurationEditorModel implements ReferenceTypeSourceBaseConfigurationPersist {