summaryrefslogtreecommitdiffhomepage
path: root/libs/cbi/htdocs/luci-static/resources/cbi.js
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-08-04 17:35:44 +0000
committerSteven Barth <steven@midlink.org>2008-08-04 17:35:44 +0000
commit3d1f9b05e9ff165f5ba74c46f167fb73dbbf5bc9 (patch)
treeee5d880a0d09bf5cdb87663de4c67b416a91a545 /libs/cbi/htdocs/luci-static/resources/cbi.js
parent084db952ce2aa302a42f35fa34866f34cb06ba99 (diff)
libs/cbi: Optimized Comboboxes
Diffstat (limited to 'libs/cbi/htdocs/luci-static/resources/cbi.js')
-rw-r--r--libs/cbi/htdocs/luci-static/resources/cbi.js68
1 files changed, 36 insertions, 32 deletions
diff --git a/libs/cbi/htdocs/luci-static/resources/cbi.js b/libs/cbi/htdocs/luci-static/resources/cbi.js
index 38e27d8f43..7cb2f7c1dc 100644
--- a/libs/cbi/htdocs/luci-static/resources/cbi.js
+++ b/libs/cbi/htdocs/luci-static/resources/cbi.js
@@ -60,46 +60,50 @@ function cbi_bind(obj, type, callback, mode) {
function cbi_combobox(id, values, def, man) {
var obj = document.getElementById(id)
- if (obj.value == "" || values[obj.value]) {
- var sel = document.createElement("select")
- obj.parentNode.appendChild(sel)
+ var sel = document.createElement("select");
+ obj.parentNode.appendChild(sel);
- if (obj.value == "") {
- var optdef = document.createElement("option")
- optdef.value = ""
- optdef.appendChild(document.createTextNode(def))
- sel.appendChild(optdef)
- }
-
- for (var i in values) {
- var opt = document.createElement("option")
- opt.value = i
+ if (obj.value == "") {
+ var optdef = document.createElement("option");
+ optdef.value = "";
+ optdef.appendChild(document.createTextNode(def));
+ sel.appendChild(optdef);
+ } else if (!values[obj.value]) {
+ var opt = document.createElement("option");
+ opt.value = obj.value;
+ opt.selected = "selected";
+ opt.appendChild(document.createTextNode(obj.value));
+ sel.appendChild(opt);
+ }
- if (obj.value == i) {
- opt.selected = "selected"
- }
+ for (var i in values) {
+ var opt = document.createElement("option");
+ opt.value = i;
- opt.appendChild(document.createTextNode(values[i]))
- sel.appendChild(opt)
+ if (obj.value == i) {
+ opt.selected = "selected";
}
- var optman = document.createElement("option")
- optman.value = ""
- optman.appendChild(document.createTextNode(man))
- sel.appendChild(optman)
+ opt.appendChild(document.createTextNode(values[i]));
+ sel.appendChild(opt);
+ }
+
+ var optman = document.createElement("option");
+ optman.value = "";
+ optman.appendChild(document.createTextNode(man));
+ sel.appendChild(optman);
- obj.style.display = "none"
+ obj.style.display = "none";
- cbi_bind(sel, "change", function() {
- obj.value = sel.options[sel.selectedIndex].value
+ cbi_bind(sel, "change", function() {
+ obj.value = sel.options[sel.selectedIndex].value;
- if (sel.selectedIndex == sel.options.length - 1) {
- obj.style.display = "inline"
- sel.parentNode.removeChild(sel)
- obj.focus()
- }
- })
- }
+ if (sel.selectedIndex == sel.options.length - 1) {
+ obj.style.display = "inline";
+ sel.parentNode.removeChild(sel);
+ obj.focus();
+ }
+ })
}
function cbi_combobox_init(id, values, def, man) {