luci-base: cbi.js: update dependencies after widgets have been rendered
authorJo-Philipp Wich <jo@mein.io>
Sat, 14 Sep 2019 15:20:41 +0000 (17:20 +0200)
committerJo-Philipp Wich <jo@mein.io>
Sat, 14 Sep 2019 15:20:41 +0000 (17:20 +0200)
Fixes: #3066
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/cbi.js

index 9144fbaf62e8a2d219d04519d9b07a3f24514111..4c3128bfd12272027c9f4deca9b6e7068086a18d 100644 (file)
@@ -314,18 +314,20 @@ function cbi_init() {
                i.addEventListener('mouseout', handler);
        });
 
+       var tasks = [];
+
        document.querySelectorAll('[data-ui-widget]').forEach(function(node) {
                var args = JSON.parse(node.getAttribute('data-ui-widget') || '[]'),
                    widget = new (Function.prototype.bind.apply(L.ui[args[0]], args)),
                    markup = widget.render();
 
-               Promise.resolve(markup).then(function(markup) {
+               tasks.push(Promise.resolve(markup).then(function(markup) {
                        markup.addEventListener('widget-change', cbi_d_update);
                        node.parentNode.replaceChild(markup, node);
-               });
+               }));
        });
 
-       cbi_d_update();
+       Promise.all(tasks).then(cbi_d_update);
 }
 
 function cbi_validate_form(form, errmsg)