G
Gregor Kofler
Refactoring my old DualSelectBox [1], I thought it would be much smarter
to get rid of the new Option() stuff, and instead just switch childNodes
between the two select elements. Something like that:
function shiftSelectedOptions(src, dest) {
var i, len, opts = [];
for(i = 0, len = src.options.length; i < len; i++) {
if (src.options.selected) {
opts.push(src.options);
}
}
for(i = 0, len = opts.length; i < len; i++) {
opts.selected = false;
dest.appendChild(opts);
}
}
Works as expected in all reasonable browsers, alas IE6 (and perhaps 7,
too) has issues. The childNodes get removed from the source element, and
get appended to the destination element - at least that's what this
abysmal DOM Explorer tells me. But they stay invisible - as if some sort
of "refresh" is missing.
To add to the confusion: The above function gets called upon
initialization of the widget, and there it works (i.e. the options show
up), despite nothing explicit happens to the DOM after calling above
function. Just subsequent adding fails.
init() {
....
sourceBox = destinationBox.cloneNode(false);
destinationBox.parentNode.insertBefore(sourceBox, destinationBox);
shiftSelectedOptions(destinationBox, sourceBox);
window.alert("check!"); // options visible
}
BTW: The childNodes of the select elements get cleaned, i.e. all nodes
that are not of the "OPTION" type get removed, including plain textnodes.
Any idea, how to deal with this issue?
Gregor
[1]
http://web.gregorkofler.com/index.php?page=form_enhancements
to get rid of the new Option() stuff, and instead just switch childNodes
between the two select elements. Something like that:
function shiftSelectedOptions(src, dest) {
var i, len, opts = [];
for(i = 0, len = src.options.length; i < len; i++) {
if (src.options.selected) {
opts.push(src.options);
}
}
for(i = 0, len = opts.length; i < len; i++) {
opts.selected = false;
dest.appendChild(opts);
}
}
Works as expected in all reasonable browsers, alas IE6 (and perhaps 7,
too) has issues. The childNodes get removed from the source element, and
get appended to the destination element - at least that's what this
abysmal DOM Explorer tells me. But they stay invisible - as if some sort
of "refresh" is missing.
To add to the confusion: The above function gets called upon
initialization of the widget, and there it works (i.e. the options show
up), despite nothing explicit happens to the DOM after calling above
function. Just subsequent adding fails.
init() {
....
sourceBox = destinationBox.cloneNode(false);
destinationBox.parentNode.insertBefore(sourceBox, destinationBox);
shiftSelectedOptions(destinationBox, sourceBox);
window.alert("check!"); // options visible
}
BTW: The childNodes of the select elements get cleaned, i.e. all nodes
that are not of the "OPTION" type get removed, including plain textnodes.
Any idea, how to deal with this issue?
Gregor
[1]
http://web.gregorkofler.com/index.php?page=form_enhancements