From 23b7dade2643aa9838c17b6a669ce6cf1d8ab438 Mon Sep 17 00:00:00 2001
From: Samuel Gaist <samuel.gaist@idiap.ch>
Date: Thu, 19 Jul 2018 12:03:18 +0200
Subject: [PATCH] [experiments][js][panels] Handle empty choice case for string
 field

String fields should provide all the possible values that
a user can select. But if for some reason the field is missing,
the interface loading will break. This patch fixes that by
setting the default value as only choice.
---
 .../static/experiments/js/panels.js           | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/beat/web/experiments/static/experiments/js/panels.js b/beat/web/experiments/static/experiments/js/panels.js
index fa226f91a..bcc99550e 100644
--- a/beat/web/experiments/static/experiments/js/panels.js
+++ b/beat/web/experiments/static/experiments/js/panels.js
@@ -2053,15 +2053,22 @@ beat.experiments.panels.Parameters.prototype._createStringControls = function(
 
   var value = (parameter_values[parameter.name] !== undefined ? parameter_values[parameter.name] : parameter.default_value);
 
-  for (var i = 0; i < parameter.choices.length; ++i)
-  {
+  if (parameter.choices === undefined) {
     var option   = document.createElement('option');
-    option.text  = parameter.choices[i];
-    option.value = parameter.choices[i];
+    option.text  = value;
+    option.value = value;
     select.appendChild(option);
+  } else {
+    for (var i = 0; i < parameter.choices.length; ++i)
+    {
+      var option   = document.createElement('option');
+      option.text  = parameter.choices[i];
+      option.value = parameter.choices[i];
+      select.appendChild(option);
 
-    if (option.value == value)
-      select.selectedIndex = i;
+      if (option.value == value)
+        select.selectedIndex = i;
+    }
   }
 
   $(select).change(function() {
-- 
GitLab