From aee61f2c69cd4e37a56ccbbd837cff5f50a22d4b Mon Sep 17 00:00:00 2001
From: Alex ORLUC <alex.orluc@maarch.org>
Date: Wed, 21 Oct 2020 16:25:25 +0000
Subject: [PATCH] FEAT #15011 TIME 0:15 fix validator

(cherry picked from commit 28c4186eef7cfe6ea5d9341668cbd4c52dfa9b5d)
---
 .../indexing-form/indexing-form.component.ts          | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts
index dd79d09d690..7fe3cb8b9ef 100755
--- a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts
+++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts
@@ -888,6 +888,8 @@ export class IndexingFormComponent implements OnInit {
             if (field.mandatory) {
                 valArr.push(Validators.required);
                 valArr.push(this.requireDestValidator({ 'isDest': '' }));
+            } else {
+                valArr.push(this.requireDestValidatorOrEmpty({ 'isDest': '' }));
             }
 
             this.arrFormControl['diffusionList'] = new FormControl({ value: null, disabled: false });
@@ -908,6 +910,15 @@ export class IndexingFormComponent implements OnInit {
         };
     }
 
+    requireDestValidatorOrEmpty(error: ValidationErrors): ValidatorFn {
+        return (control: AbstractControl): { [key: string]: any } => {
+            if (!control.value) {
+                return null;
+            }
+            return control.value.filter((item: any) => item.mode === 'dest').length > 0 || this.functions.empty(this.arrFormControl['destination'].value) ? null : error;
+        };
+    }
+
     regexValidator(regex: RegExp, error: ValidationErrors): ValidatorFn {
         return (control: AbstractControl): { [key: string]: any } => {
             if (!control.value) {
-- 
GitLab