From: Jo-Philipp Wich Date: Sat, 14 Sep 2019 15:20:41 +0000 (+0200) Subject: luci-base: cbi.js: update dependencies after widgets have been rendered X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=208bf47a33d5b6f1febd51785958ffefe25afc64;p=oweals%2Fluci.git luci-base: cbi.js: update dependencies after widgets have been rendered Fixes: #3066 Signed-off-by: Jo-Philipp Wich --- diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js index 9144fbaf6..4c3128bfd 100644 --- a/modules/luci-base/htdocs/luci-static/resources/cbi.js +++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js @@ -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)