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 {