luci-base: cbi.js: find dropdown and browser instances early
authorJo-Philipp Wich <jo@mein.io>
Tue, 10 Sep 2019 15:07:36 +0000 (17:07 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 10 Sep 2019 15:10:36 +0000 (17:10 +0200)
Gather dropdown and file browser widget nodes early, before initializing
dynamic list widgets as dynlists invoke a dependency update which in turn
might remove widget nodes from dom before they have been initialized.

Ref: https://github.com/openwrt/luci/issues/2997#issuecomment-524251601
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/cbi.js

index fa61cf6447ebc4e0cb1c68f132a04fc943620e0a..0de7bcb9cac52462aad520089056d13d756822b2 100644 (file)
@@ -736,7 +736,9 @@ function cbi_d_update() {
 }
 
 function cbi_init() {
-       var nodes;
+       var dropdowns = document.querySelectorAll('.cbi-dropdown'),
+           browsers = document.querySelectorAll('[data-browser]'),
+           nodes;
 
        nodes = document.querySelectorAll('[data-strings]');
 
@@ -808,8 +810,8 @@ function cbi_init() {
                                   node.getAttribute('data-type'));
        }
 
-       document.querySelectorAll('.cbi-dropdown').forEach(cbi_dropdown_init);
-       document.querySelectorAll('[data-browser]').forEach(cbi_browser_init);
+       dropdowns.forEach(cbi_dropdown_init);
+       browsers.querySelectorAll('[data-browser]').forEach(cbi_browser_init);
 
        document.querySelectorAll('.cbi-tooltip:not(:empty)').forEach(function(s) {
                s.parentNode.classList.add('cbi-tooltip-container');