luci-base: cbi: properly handle dependant elements without parent
authorJo-Philipp Wich <jow@openwrt.org>
Wed, 10 Feb 2016 18:29:29 +0000 (19:29 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Wed, 10 Feb 2016 18:29:34 +0000 (19:29 +0100)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
modules/luci-base/htdocs/luci-static/resources/cbi.js

index a1491cc6635a36878acb8eea16648cbcc4a2fe96..f58306954ecabb8aa859de919c598c6515bb1b7b 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' : '';
        }