From d5990f8f48630a031f3a493dba95a9a57bbdcc48 Mon Sep 17 00:00:00 2001 From: Pierre-Narcisi Date: Mon, 9 Dec 2024 14:32:16 +0100 Subject: [PATCH] fix(mapping) fix mandatory field on synthese import --- frontend/src/app/GN2CommonModule/form/form.service.ts | 1 + .../imports/services/mappings/field-mapping.service.ts | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/src/app/GN2CommonModule/form/form.service.ts b/frontend/src/app/GN2CommonModule/form/form.service.ts index 6fe0312923..923920f339 100644 --- a/frontend/src/app/GN2CommonModule/form/form.service.ts +++ b/frontend/src/app/GN2CommonModule/form/form.service.ts @@ -203,6 +203,7 @@ export class FormService { currentControl: AbstractControl ): boolean { let result = false; + if (referenceControlNames.length === 0) return true; referenceControlNames.forEach((referenceControlName) => { const referenceControl = currentControl.parent.get(referenceControlName); diff --git a/frontend/src/app/modules/imports/services/mappings/field-mapping.service.ts b/frontend/src/app/modules/imports/services/mappings/field-mapping.service.ts index aa870ecc49..0d14afddcb 100644 --- a/frontend/src/app/modules/imports/services/mappings/field-mapping.service.ts +++ b/frontend/src/app/modules/imports/services/mappings/field-mapping.service.ts @@ -267,7 +267,7 @@ export class FieldMappingService { .setValidators( this._formservice.RequiredIfControlIsNotNullValidator( mandatory_conditions, - this.fieldsByEntity.get(entity.label) + this.targetFieldsData.length > 1 ? this.fieldsByEntity.get(entity.label) : [] ) ); } @@ -277,14 +277,16 @@ export class FieldMappingService { .setValidators( this._formservice.NotRequiredIfControlIsNotNullValidator( optional_conditions, - this.fieldsByEntity.get(entity.label) + this.targetFieldsData.length > 1 ? this.fieldsByEntity.get(entity.label) : [] ) ); } else if (mandatory) { this.mappingFormGroup .get(name_field) .setValidators( - this._formservice.NotRequiredIfNoOther(this.fieldsByEntity.get(entity.label)) + this._formservice.NotRequiredIfNoOther( + this.targetFieldsData.length > 1 ? this.fieldsByEntity.get(entity.label) : [] + ) ); }