From 56759310114d05f9a4ed1c9ca03248bfd03480d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Wed, 1 Mar 2023 10:43:38 +0100
Subject: [PATCH] fix: FieldSet.updateFields(): update inputs with nub values
 in case clearing is not forced

refs #601
---
 src/app/formulaire/elements/fieldset.ts | 29 +++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/app/formulaire/elements/fieldset.ts b/src/app/formulaire/elements/fieldset.ts
index 7b709eb76..73e6b8535 100644
--- a/src/app/formulaire/elements/fieldset.ts
+++ b/src/app/formulaire/elements/fieldset.ts
@@ -4,7 +4,8 @@ import {
     IProperties,
     Observer,
     Nub,
-    enumValueFromString
+    enumValueFromString,
+    ParamValueMode
 } from "jalhyd";
 
 import { FormulaireElement } from "./formulaire-element";
@@ -215,8 +216,32 @@ export class FieldSet extends FormulaireElement implements IProperties {
     public updateFields(forceClear: boolean) {
         if (forceClear) {
             this.clearFields();
+            this.parseFields();
         }
-        this.parseFields();
+        else {
+            const nub = this.parentForm.currentNub;
+            for (const e of this.parentForm.allFormElements) {
+                if (e instanceof NgParameter) {
+                    const p: ParamDefinition = nub.getParameter(e.symbol);
+                    switch (e.paramDefinition.valueMode) {
+                        case ParamValueMode.SINGLE:
+                            e.setValue(this, p.singleValue);
+                            break;
+
+                        case ParamValueMode.MINMAX:
+                            e.setMinValue(this, p.min);
+                            e.setMaxValue(this, p.max);
+                            e.setStepValue(this, p.step);
+                            break;
+
+                        case ParamValueMode.LISTE:
+                            e.setValueList(this, p.valueList);
+                            break;
+                    }
+                }
+            }
+        }
+
         this.updateLocalisation();
 
         // for all select fields known by the form, set selected value
-- 
GitLab