luci-base: cbi: fix reverse field order after dependency change
authorJo-Philipp Wich <jow@openwrt.org>
Mon, 18 Jan 2016 17:59:14 +0000 (18:59 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Mon, 18 Jan 2016 17:59:19 +0000 (18:59 +0100)
When fields got removed and readded due to unsatisfied dependencies, they
got inserted in reverse order into the dom.

Fix this issue by properly passing the element index.

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
modules/luci-base/htdocs/luci-static/resources/cbi.js

index 81cc65778464b6d9956eb711adc31b11a61d9c92..8bf94a6c5097be817e563bcaaa301b54f3f8c84b 100644 (file)
@@ -506,10 +506,11 @@ function cbi_init() {
        var nodes = document.querySelectorAll('[data-depends]');
 
        for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
-               var deps = JSON.parse(node.getAttribute('data-depends'));
-               if (deps.length > 0) {
-                       for (var alt = 0; alt < deps.length; alt++) {
-                               cbi_d_add(node, deps[alt], i);
+               var index = parseInt(node.getAttribute('data-index'), 10);
+               var depends = JSON.parse(node.getAttribute('data-depends'));
+               if (!isNaN(index) && depends.length > 0) {
+                       for (var alt = 0; alt < depends.length; alt++) {
+                               cbi_d_add(node, depends[alt], index);
                        }
                }
        }