libs/cbi: Optimized Comboboxes

This commit is contained in:
Steven Barth 2008-08-04 17:35:44 +00:00
parent 084db952ce
commit 3d1f9b05e9
3 changed files with 44 additions and 40 deletions

View file

@ -4,5 +4,5 @@ cbi_invalid = "Error: Invalid input value"
cbi_addopt = "-- Additional Field --" cbi_addopt = "-- Additional Field --"
cbi_optional = " (optional)" cbi_optional = " (optional)"
cbi_sectempty = "This section contains no values yet" cbi_sectempty = "This section contains no values yet"
cbi_manual = "-- manual --" cbi_manual = "-- custom --"
cbi_select = "-- Please choose --" cbi_select = "-- Please choose --"

View file

@ -3,5 +3,5 @@ cbi_del = "Eintrag entfernen"
cbi_invalid = "Error: Ungültige Eingabe" cbi_invalid = "Error: Ungültige Eingabe"
cbi_addopt = "-- Zusätzliches Feld --" cbi_addopt = "-- Zusätzliches Feld --"
cbi_sectempty = "Diese Sektion enthält noch keine Einträge" cbi_sectempty = "Diese Sektion enthält noch keine Einträge"
cbi_manual = "-- manuell --" cbi_manual = "-- benutzerdefiniert --"
cbi_select = "-- Bitte auswählen --" cbi_select = "-- Bitte auswählen --"

View file

@ -60,46 +60,50 @@ function cbi_bind(obj, type, callback, mode) {
function cbi_combobox(id, values, def, man) { function cbi_combobox(id, values, def, man) {
var obj = document.getElementById(id) var obj = document.getElementById(id)
if (obj.value == "" || values[obj.value]) { var sel = document.createElement("select");
var sel = document.createElement("select") obj.parentNode.appendChild(sel);
obj.parentNode.appendChild(sel)
if (obj.value == "") { if (obj.value == "") {
var optdef = document.createElement("option") var optdef = document.createElement("option");
optdef.value = "" optdef.value = "";
optdef.appendChild(document.createTextNode(def)) optdef.appendChild(document.createTextNode(def));
sel.appendChild(optdef) 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);
} }
for (var i in values) { for (var i in values) {
var opt = document.createElement("option") var opt = document.createElement("option");
opt.value = i opt.value = i;
if (obj.value == i) { if (obj.value == i) {
opt.selected = "selected" opt.selected = "selected";
} }
opt.appendChild(document.createTextNode(values[i])) opt.appendChild(document.createTextNode(values[i]));
sel.appendChild(opt) sel.appendChild(opt);
} }
var optman = document.createElement("option") var optman = document.createElement("option");
optman.value = "" optman.value = "";
optman.appendChild(document.createTextNode(man)) optman.appendChild(document.createTextNode(man));
sel.appendChild(optman) sel.appendChild(optman);
obj.style.display = "none" obj.style.display = "none";
cbi_bind(sel, "change", function() { cbi_bind(sel, "change", function() {
obj.value = sel.options[sel.selectedIndex].value obj.value = sel.options[sel.selectedIndex].value;
if (sel.selectedIndex == sel.options.length - 1) { if (sel.selectedIndex == sel.options.length - 1) {
obj.style.display = "inline" obj.style.display = "inline";
sel.parentNode.removeChild(sel) sel.parentNode.removeChild(sel);
obj.focus() obj.focus();
} }
}) })
}
} }
function cbi_combobox_init(id, values, def, man) { function cbi_combobox_init(id, values, def, man) {