IE (naturally) select-option bug, workaround?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gregor Kofler

    IE (naturally) select-option bug, workaround?

    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 shiftSelectedOp tions(src, dest) {
    var i, len, opts = [];
    for(i = 0, len = src.options.len gth; i < len; i++) {
    if (src.options[i].selected) {
    opts.push(src.o ptions[i]);
    }
    }
    for(i = 0, len = opts.length; i < len; i++) {
    opts[i].selected = false;
    dest.appendChil d(opts[i]);
    }
    }

    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.inse rtBefore(source Box, destinationBox) ;
    shiftSelectedOp tions(destinati onBox, sourceBox);
    window.alert("c heck!"); // 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://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
    http://web.gregorkofler.com ::: meine JS-Spielwiese
    http://www.image2d.com ::: Bildagentur für den alpinen Raum
  • Doug Gunnoe

    #2
    Re: IE (naturally) select-option bug, workaround?

    On Jun 29, 4:41 pm, Gregor Kofler <use...@gregork ofler.atwrote:
    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 shiftSelectedOp tions(src, dest) {
    var i, len, opts = [];
    for(i = 0, len = src.options.len gth; i < len; i++) {
    if (src.options[i].selected) {
    opts.push(src.o ptions[i]);
    }
    }
    for(i = 0, len = opts.length; i < len; i++) {
    opts[i].selected = false;
    dest.appendChil d(opts[i]);
    }
    >
    }
    >
    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.
    Hi Greg. I tried your script in IE7 and Firefox, and in both cases the
    nodes were removed from the 'src' element. I was a little confused by
    your question above. Is this what you need to happen, or not?

    When I tried it, after the childNodes were appended to the 'dest'
    element, they were visible in both IE7 and Firefox in the 'dest'
    element. I don't have IE6 handy at the moment.

    doing, opts.push(src.o ptions[i].cloneNode(true )) keeps the drop down
    option available in the original 'src' element. But, I'm not sure the
    ramifications of using cloneNode on form elements and then later
    submitting the form.
    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.
    And I don't understand why it would do that, unless the other nodes
    were also children of the option nodes.

    Comment

    • Gregor Kofler

      #3
      Re: IE (naturally) select-option bug, workaround?

      Doug Gunnoe meinte:
      Hi Greg. I tried your script in IE7 and Firefox, and in both cases the
      nodes were removed from the 'src' element. I was a little confused by
      your question above. Is this what you need to happen, or not?
      Yes. They should be moved from one select element to the other.
      When I tried it, after the childNodes were appended to the 'dest'
      element, they were visible in both IE7 and Firefox in the 'dest'
      element. I don't have IE6 handy at the moment.
      WWW sources state, that the select elements were completely "redesigned "
      in IE7.
      doing, opts.push(src.o ptions[i].cloneNode(true )) keeps the drop down
      option available in the original 'src' element. But, I'm not sure the
      ramifications of using cloneNode on form elements and then later
      submitting the form.
      Not sure about that, too. However, since a submit listener has to
      prepare the data anyway, one could always stuff the data in some hidden
      input (currently the submit handler sets selected on all options of the
      destination box).
      >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.
      >
      And I don't understand why it would do that, unless the other nodes
      were also children of the option nodes.
      IE6 also has comparable problems when textnodes are mixed with the
      options. Plus: Iterating through childnodes is easier. In a first
      attempt I removed all non-option elements.


      Gregor


      --
      http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
      http://web.gregorkofler.com ::: meine JS-Spielwiese
      http://www.image2d.com ::: Bildagentur für den alpinen Raum

      Comment

      • korisu

        #4
        Re: IE (naturally) select-option bug, workaround?

        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.
        I haven't checked your example here, but I revamped a similar option-
        swapping widget at work several months ago, and ran into similar
        behavior (albeit with insertBefore instead of appendChild), and here's
        what I found.

        The option is actually there, but IE needs a trigger to repaint the
        element before it'll show up. I found that it reappeared onmouseover
        when I was debugging it. In the end, the following worked when I used
        it after any DOM-altering code:

        function repaintIE (obj) {
        if (obj && obj.style) {
        obj.style.visib ility = "hidden";
        obj.style.visib ility = "";
        }
        }

        Hope that helps!

        Comment

        • Gregor Kofler

          #5
          Re: IE (naturally) select-option bug, workaround?

          korisu meinte:
          The option is actually there, but IE needs a trigger to repaint the
          element before it'll show up.
          Exactly. That's what I figured out, too.
          I found that it reappeared onmouseover
          when I was debugging it. In the end, the following worked when I used
          it after any DOM-altering code:
          >
          function repaintIE (obj) {
          if (obj && obj.style) {
          obj.style.visib ility = "hidden";
          obj.style.visib ility = "";
          }
          }
          I tried something like replacing the select-element with itself. Didn't
          work. I'll look into your suggestions, thanks.

          Gregor



          --
          http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
          http://web.gregorkofler.com ::: meine JS-Spielwiese
          http://www.image2d.com ::: Bildagentur für den alpinen Raum

          Comment

          • benlevy3@gmail.com

            #6
            Re: IE (naturally) select-option bug, workaround?

            I found this posting while I was working on an issue.

            The cloneNode (true) works great in IE7, but in IE6 it does not show
            (as the original post states). The repaint suggestion works GREAT!

            Thanks all.

            On Jul 1, 6:17 am, Gregor Kofler <use...@gregork ofler.atwrote:
            korisu meinte:
            >
            The option is actually there, but IE needs a trigger to repaint the
            element before it'll show up.
            >
            Exactly. That's what I figured out, too.
            >
            I found that it reappeared onmouseover
            when I was debugging it. In the end, the following worked when I used
            it after any DOM-altering code:
            >
            function repaintIE (obj) {
              if (obj && obj.style) {
                obj.style.visib ility = "hidden";
                obj.style.visib ility = "";
              }
            }
            >
            I tried something like replacing the select-element with itself. Didn't
            work. I'll look into your suggestions, thanks.
            >
            Gregor
            >
            --http://photo.gregorkof ler.at::: Landschafts- und Reisefotografie http://web.gregorkofle r.com ::: meine JS-Spielwiesehttp://www.image2d.com     ::: Bildagentur für den alpinen Raum

            Comment

            Working...