From 61baefb7f6b4d5bc19100b7c70b9ef8c7d921453 Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Thu, 10 Mar 2022 13:18:57 +0100 Subject: [PATCH 1/2] cleanCheckbox --- .../add-restau/add-restau.component.ts | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/app/admin-component/add-restau/add-restau.component.ts b/src/app/admin-component/add-restau/add-restau.component.ts index 9f86c08..6be2b72 100644 --- a/src/app/admin-component/add-restau/add-restau.component.ts +++ b/src/app/admin-component/add-restau/add-restau.component.ts @@ -39,15 +39,7 @@ export class AddRestauComponent implements OnInit { //On enregistre un identifiant de restaurant, preuve qu'on est bien en MODIFICATION this.idRestauAModifier = restau.id; - // on vide les checkbox si on en a coché avant de cliquer sur une modif - this.formArrayCheckbox.controls = []; - - // on vide (pour l'affichage également) - let inputCategories = document.querySelectorAll('#checkboxes li input'); - for (let i = 0; i < inputCategories.length; i++) { - let input = inputCategories[i] as HTMLInputElement - input.checked = false; - } + this.cleanCheckbox(); if (restau.typerestaus != undefined && restau.typerestaus != null) { for (let index = 0; index < restau.typerestaus.length; index++) { @@ -123,17 +115,26 @@ export class AddRestauComponent implements OnInit { this.idRestauAModifier != null && this.idRestauAModifier != undefined) { this.apiBackService.modifRestaurant(restaurant).subscribe( - resp => {this.idRestauAModifier = 0 + resp => { + this.idRestauAModifier = 0 // Une fois le retour du subscribe qui est la preuve du bon enregistrement alors // On reinitialise identifiant restau a 0 pour se remettre en mode CREATION + + this.initForm(EMPTY_RESTAU); + this.cleanCheckbox(); - this.router.navigate(['restaurants']) + //this.router.navigate(['restaurants']) } ) } else { // sinon on crée un restau this.apiBackService.addRestaurant(restaurant).subscribe( - resp => - this.router.navigate(['restaurants']) + resp => { + this.initForm(EMPTY_RESTAU) + + this.cleanCheckbox(); + + //this.router.navigate(['restaurants']) + } ); } } else { @@ -166,6 +167,18 @@ export class AddRestauComponent implements OnInit { } } + cleanCheckbox(){ + // on vide les checkbox si on en a coché avant de cliquer sur une modif + this.formArrayCheckbox.controls = []; + + // on vide (pour l'affichage également) + let inputCategories = document.querySelectorAll('#checkboxes li input'); + for (let i = 0; i < inputCategories.length; i++) { + let input = inputCategories[i] as HTMLInputElement + input.checked = false; + } + } + ngOnDestroy() { if (this.idRestau) { From fb972c6f1dbd4d9bd0bd3a82c80cbe149d6b837c Mon Sep 17 00:00:00 2001 From: Thomas Cardon Date: Thu, 10 Mar 2022 13:20:12 +0100 Subject: [PATCH 2/2] cleanCheckbox --- src/app/admin-component/add-restau/add-restau.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/admin-component/add-restau/add-restau.component.ts b/src/app/admin-component/add-restau/add-restau.component.ts index 6be2b72..3b2ce0d 100644 --- a/src/app/admin-component/add-restau/add-restau.component.ts +++ b/src/app/admin-component/add-restau/add-restau.component.ts @@ -131,7 +131,7 @@ export class AddRestauComponent implements OnInit { resp => { this.initForm(EMPTY_RESTAU) - this.cleanCheckbox(); + this.cleanCheckbox() //this.router.navigate(['restaurants']) }