From b43145b20f953d6f8b9d7dc879e8b959cd5ab547 Mon Sep 17 00:00:00 2001
From: Jean-Pascal <jean-pascal.aubry@inrae.fr>
Date: Tue, 12 Dec 2023 10:14:46 +0000
Subject: [PATCH] fix:  implement update function when another macro rugo is
 selected

---
 .../definition/form-macrorugo-remous.ts       | 48 +++++++++----------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/src/app/formulaire/definition/form-macrorugo-remous.ts b/src/app/formulaire/definition/form-macrorugo-remous.ts
index 6eb5a1c43..5fdd1c8be 100644
--- a/src/app/formulaire/definition/form-macrorugo-remous.ts
+++ b/src/app/formulaire/definition/form-macrorugo-remous.ts
@@ -16,6 +16,7 @@ export class FormulaireMacrorugoRemous extends FormulaireFixedVar {
         }
         if (pam !== undefined) {
             props.setPropValue("nubMacroRugo", pam.uid);
+
         }
         return super.initNub(props);
     }
@@ -40,6 +41,7 @@ export class FormulaireMacrorugoRemous extends FormulaireFixedVar {
     }
 
     protected reaffectResultComponents() {
+        console.log("reaffect");
         const mrr = this.currentNub as MacrorugoRemous;
         mrr.syncSectionMacroRugo();
         
@@ -81,30 +83,28 @@ export class FormulaireMacrorugoRemous extends FormulaireFixedVar {
 
     // interface Observer
 
-    // public update(sender: IObservable, data: any) {
-    //     // copied from FormDefinition, to avoid calling super.update() that would trigger an unwanted this.refreshFieldsets();
-    //     if (sender instanceof Nub) {
-    //         switch (data.action) {
-    //             case "resultUpdated":
-    //                 // forward Nub results update notification to FormCompute objects
-    //                 this.reaffectResultComponents();
-    //                 break;
-    //         }
-    //     }
-    //     // copied from FormFixedVar, to avoid calling super.update()
-    //     if (data.action === "propertyChange") {
-    //         this.reset();
-    //     }
-
-    //     if (sender instanceof SelectField) {
-    //         this.reset(); // reset results
-    //         console.log("update", data.action)
-    //         if (sender.id === "select_target_pam" && data.action === "select") {
-    //             // update Verificateur property: Pass to check
-    //             this._currentNub.setPropValue("nubToVerify", data.value ? data.value.value : undefined);
-    //         } 
-    //     }
-    // }
+    public update(sender: IObservable, data: any, props?: Props) {
+        // copied from FormDefinition, to avoid calling super.update() that would trigger an unwanted this.refreshFieldsets();
+        if (sender instanceof Nub) {
+            switch (data.action) {
+                case "resultUpdated":
+                    // forward Nub results update notification to FormCompute objects
+                    this.reaffectResultComponents();
+                    break;
+            }
+        }
+        // copied from FormFixedVar, to avoid calling super.update()
+        if (data.action === "propertyChange") {
+            this.reset();
+        }
+
+        if (sender instanceof SelectField) {
+            this.reset(); // reset results
+            if (sender.id === "select_target_pam" && data.action === "select") {
+                this._currentNub.setPropValue("nubMacroRugo",data.value.value);
+            } 
+        }
+    }
 
     public resetFormResults() {
         this._remousResults.reset();
-- 
GitLab