luci-base: cbi.js: update dependencies after widgets have been rendered

Fixes: #3066
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2019-09-14 17:20:41 +02:00
parent 7c9d1a259c
commit 208bf47a33

View 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)