From 835386cec974e67e40b8d905ad66792f53ff6ada Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Fri, 27 Jan 2023 15:52:29 +0100
Subject: [PATCH] fix: SelectFieldDeviceStructureType defaut value

refs #592
---
 .../select/select-field-device-structure-type.ts       | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/app/formulaire/elements/select/select-field-device-structure-type.ts b/src/app/formulaire/elements/select/select-field-device-structure-type.ts
index 7b188d114..0d1ce351d 100644
--- a/src/app/formulaire/elements/select/select-field-device-structure-type.ts
+++ b/src/app/formulaire/elements/select/select-field-device-structure-type.ts
@@ -21,6 +21,14 @@ export class SelectFieldDeviceStructureType extends SelectField {
         this._configDefaultValue = json["default"];
     }
 
+    /**
+    * get discharge law linked to this select's nub
+    */
+    private get structureType(): StructureType {
+        const child = this.nub.getChildren()[this.parent.indexAsKid()];
+        return child.getPropValue("structureType");
+    }
+
     protected populate() {
         // possible values depend on CalcType
         for (const st in (this.nub as ParallelStructure).getLoisAdmissibles()) {
@@ -30,6 +38,6 @@ export class SelectFieldDeviceStructureType extends SelectField {
     }
 
     protected initSelectedValue() {
-        this.findAndSetDefaultValue();
+        this.findAndSetDefaultValue(StructureType[this.structureType]);
     }
 }
-- 
GitLab