#993 bug
Jean-Philippe Encausse

Bug in readAttribute() for Form with Input named children

Reported by Jean-Philippe Encausse | February 18th, 2010 @ 04:57 PM | in 2.0

Hi,
It seems there is a strange bug/behavior with method readAttribute() for FORM that contains an imput named "children" with IE all version.

if (Prototype.Browser.IE) {
  var t = Element._attributeTranslations.read;
  if (element.tagName.toUpperCase() == 'FORM' &&  
      !/^((child|parent)Node|(next|previous)Sibling)$/.test(name) && 
      element.children[name]){ 
    element = $(element.cloneNode(false)); 
  }
...

The 3rd "If" condition check "element.children". The parameter "element" is a FORM (1st condition). So if FORM contains an input or inputs named "children" there will be a side effect.

Prototype: version 1.6.1

Note:


Edit 02/25/2010

I made a rollback on Scruiptaculous patch to use default protoype function:

  readAttribute: function(element, name) {
    element = $(element);
    if (Prototype.Browser.IE) {
      var t = Element._attributeTranslations.read; 
      if (t.values[name]) return t.values[name](element, name);
      if (t.names[name]) name = t.names[name];
      if (name.include(':')) {
        return (!element.attributes || !element.attributes[name]) ? null :
         element.attributes[name].value;
      }
    }
    return element.getAttribute(name);
  },

I have a form with the following code:

<form id='myId' name='myName'>
  <input name='id' value='test1' />
  <input name='children' value='test2-1' />
  <input name='children' value='test2-2' />
</form>

With IE6 i call the followin code:

alert($(document.myName).identify());

=> It prints "Object" so I put logs:

  readAttribute: function(element, name) {
    element = $(element);
    if (Prototype.Browser.IE) {
      var t = Element._attributeTranslations.read; 
      if (t.values[name]) return t.values[name](element, name);
      if (t.names[name]) name = t.names[name];
      if (name.include(':')) {
        return (!element.attributes || !element.attributes[name]) ? null :
         element.attributes[name].value;
      }
    }
    alert('Value: '+element.getAttribute(name) + ' => ' + element.attributes[name].value);
    return element.getAttribute(name);
  },

It prints "Value: [Object] => myId"

  • Why does alert() is called (i'm using IE6) ?
  • Why testing "name.include(':')" I don't understand ?
  • How can I fix this ?

Regards,
Jp

Comments and changes to this ticket

  • Tobie Langel
  • Tisho Georgiev

    Tisho Georgiev March 1st, 2010 @ 04:45 PM

    • Tag set to section:dom
    • State changed from “new” to “bug”

    Hi JP,

    You're experiencing this behavior, because when you call identify() on the form, getAttribute() in IE will wrongly return the element by the name of 'id' that belongs to the form (in this case an ), and not the value of the 'id' attribute. You can work around this by not naming any input fields 'id', or anything else that might coincide with an attribute name that you're using, because IE will essentially overwrite the attribute getter with the element that corresponds to that name.

    A way to resolve this bug would be to have a separate check in readAttribute, which accounts for accessing attributes of forms, but that would probably have a significant performance impact. What does everyone else think?

  • Jean-Philippe Encausse

    Jean-Philippe Encausse March 1st, 2010 @ 05:17 PM

    Hi,
    Thanks, I can't rename our inputs (id, action, children) because they are used in our CMS since 8 years. (They are binded to a JavaBean that automaticaly decode request parameters and fill Java Object).

    With years we use more and more JavaScript and discover some IE6 bug :(

    We have made a cludge patch by commenting "if (name.include(':')) {" but it is really difficult to understand side effects.

    May be a better/cleaner workaround ?

  • Tobie Langel

    Tobie Langel March 1st, 2010 @ 05:35 PM

    • Milestone set to 2.0

    It's worth fixing that if possible. I'll look into asap, but most probably not before 1.7

  • Jean-Philippe Encausse

    Jean-Philippe Encausse March 1st, 2010 @ 05:38 PM

    Thanks,
    Is my workaround is correct ? Or is there too many side effects ?

  • Tobie Langel

    Tobie Langel March 1st, 2010 @ 05:44 PM

    Honestly, attributes in IE are the biggest can of worms ever.

    Cloned elements share a single attributes object, so you modification basically means that you'll get borked results reading attributes of any cloned element in IE6.

    Other than that, you should be fine.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

Pages