luci-base: cbi: properly handle dependant elements without parent
[project/luci.git] / modules / luci-base / htdocs / luci-static / resources / cbi.js
index b27c564..f583069 100644 (file)
@@ -454,7 +454,7 @@ function cbi_d_update() {
                if (node && node.parentNode && !cbi_d_check(entry.deps)) {
                        node.parentNode.removeChild(node);
                        state = true;
-               } else if ((!node || !node.parentNode) && cbi_d_check(entry.deps)) {
+               } else if (parent && (!node || !node.parentNode) && cbi_d_check(entry.deps)) {
                        var next = undefined;
 
                        for (next = parent.firstChild; next; next = next.nextSibling) {
@@ -473,7 +473,7 @@ function cbi_d_update() {
                }
 
                // hide optionals widget if no choices remaining
-               if (parent.parentNode && parent.getAttribute('data-optionals'))
+               if (parent && parent.parentNode && parent.getAttribute('data-optionals'))
                        parent.parentNode.style.display = (parent.options.length <= 1) ? 'none' : '';
        }
 
@@ -550,10 +550,14 @@ function cbi_init() {
 
        for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
                var choices = JSON.parse(node.getAttribute('data-dynlist'));
-               var options = {};
+               var options = null;
 
-               for (var j = 0; j < choices[0].length; j++)
-                       options[choices[0][j]] = choices[1][j];
+               if (choices[0] && choices[0].length) {
+                       options = {};
+
+                       for (var j = 0; j < choices[0].length; j++)
+                               options[choices[0][j]] = choices[1][j];
+               }
 
                cbi_dynlist_init(node, choices[2], choices[3], options);
        }