luci-base:adjust the code order
[project/luci.git] / modules / luci-base / htdocs / luci-static / resources / cbi.js
index c084709..0ca7e26 100644 (file)
@@ -523,13 +523,6 @@ function cbi_init() {
                }
        }
 
-       nodes = document.querySelectorAll('[data-type]');
-
-       for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
-               cbi_validate_field(node, node.getAttribute('data-optional') === 'true',
-                                  node.getAttribute('data-type'));
-       }
-
        nodes = document.querySelectorAll('[data-choices]');
 
        for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
@@ -562,6 +555,13 @@ function cbi_init() {
                cbi_dynlist_init(node, choices[2], choices[3], options);
        }
 
+       nodes = document.querySelectorAll('[data-type]');
+
+       for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
+               cbi_validate_field(node, node.getAttribute('data-optional') === 'true',
+                                  node.getAttribute('data-type'));
+       }
+
        cbi_d_update();
 }
 
@@ -592,6 +592,7 @@ function cbi_combobox(id, values, def, man, focus) {
        var obj = document.getElementById(id)
        var sel = document.createElement("select");
                sel.id = selid;
+               sel.index = obj.index;
                sel.className = obj.className.replace(/cbi-input-text/, 'cbi-input-select');
 
        if (obj.nextSibling) {
@@ -925,14 +926,14 @@ function cbi_dynlist_init(parent, datatype, optional, choices)
                        input.value = '';
 
                        cbi_dynlist_keydown({
-                               target:  se,
+                               target:  input,
                                keyCode: 8
                        });
                }
                else
                {
                        cbi_dynlist_keydown({
-                               target:  se,
+                               target:  input,
                                keyCode: 13
                        });
                }
@@ -1299,6 +1300,9 @@ String.prototype.format = function()
        var quot_esc = [/"/g, '"', /'/g, '''];
 
        function esc(s, r) {
+               if (typeof(s) !== 'string' && !(s instanceof String))
+                       return '';
+
                for( var i = 0; i < r.length; i += 2 )
                        s = s.replace(r[i], r[i+1]);
                return s;
@@ -1360,11 +1364,11 @@ String.prototype.format = function()
                                                break;
 
                                        case 'd':
-                                               subst = (+param || 0);
+                                               subst = ~~(+param || 0);
                                                break;
 
                                        case 'u':
-                                               subst = Math.abs(+param || 0);
+                                               subst = ~~Math.abs(+param || 0);
                                                break;
 
                                        case 'f':