From c68f9baf3e433db7f34d06446d205e17d5ed48cd Mon Sep 17 00:00:00 2001
From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com>
Date: Tue, 9 Feb 2021 17:59:41 +0100
Subject: [PATCH] fix(editForm): fix logic validate/close form

---
 src/app/form/form.component.html | 2 +-
 src/app/form/form.component.ts   | 8 ++++++--
 src/assets/scss/_buttons.scss    | 3 +++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/app/form/form.component.html b/src/app/form/form.component.html
index 176b86f8f..fcac27064 100644
--- a/src/app/form/form.component.html
+++ b/src/app/form/form.component.html
@@ -1040,7 +1040,7 @@
     </div>
     <div *ngIf="isEditMode && currentPage == 0" class="footerEditMode">
       <div fxLayout="row" fxLayoutAlign="center center">
-        <button class="btn-primary unique" (click)="validateForm()">Terminé</button>
+        <button class="btn-primary unique" (click)="closeEditMode()">Terminé</button>
       </div>
     </div>
   </div>
diff --git a/src/app/form/form.component.ts b/src/app/form/form.component.ts
index 03290090e..55847505a 100644
--- a/src/app/form/form.component.ts
+++ b/src/app/form/form.component.ts
@@ -612,7 +612,7 @@ export class FormComponent implements OnInit {
       let user: User;
       if (this.isEditMode) {
         this.structureService.editStructure(structure).subscribe((s: Structure) => {
-          this.router.navigateByUrl('home', { state: { data: s } });
+          this.editForm = this.createStructureForm(s);
         });
       } else {
         if (this.profile) {
@@ -671,7 +671,7 @@ export class FormComponent implements OnInit {
 
   public goToSpecificPage(numPage: number, isSave: boolean): void {
     if (isSave) {
-      this.editForm = this.createStructureForm(new Structure(this.structureForm.value));
+      this.validateForm();
     } else {
       const structure = new Structure(this.editForm.value);
       this.structureForm = this.createStructureForm(structure);
@@ -679,4 +679,8 @@ export class FormComponent implements OnInit {
     }
     this.currentPage = numPage;
   }
+
+  public closeEditMode(): void {
+    this.router.navigateByUrl('home', { state: { data: this.editForm.value } });
+  }
 }
diff --git a/src/assets/scss/_buttons.scss b/src/assets/scss/_buttons.scss
index 76f220fca..ec08d9b85 100644
--- a/src/assets/scss/_buttons.scss
+++ b/src/assets/scss/_buttons.scss
@@ -76,4 +76,7 @@
   &.small {
     width: 149px;
   }
+  &.invalid {
+    opacity: 0.4;
+  }
 }
-- 
GitLab