[Zope3-dev] formlib.pageform.pt javascript IE problems and solution

Marcin Kołoczek mkoloczek at coig.katowice.pl
Thu Feb 15 08:34:46 EST 2007


Hi!

When I was playing with widgets, I saw that current version of 
pageform.pt javascript did not work properly in IE ver 6...something ;), 
not actually matters (but worked fine in FF and Opera).

When I changed a few lines, now it works for my IE (6.sth), FF (2.0.0.1) 
and Opera(9.01) versions.
Please check if it is a proper solution to metnioned bug(?).
I'm not able to change it in svn, so if it's OK  maybe someone else 
ought to do that, please? :)

Here is the code:
<code>
<script type="text/javascript">
<!--
function toggleFormFieldHelp(ob,state) {
  // ob is the label element
  var field = findWidgetDiv(ob);
  if (field) {
    field.style.visibility = state && 'hidden' || 'visible';
    var help = document.getElementById("field-help-for-" + ob.htmlFor);
    if (help) {
      help.style.visibility = state && 'visible' || 'hidden';
    }
  }
}

function findWidgetDiv(label) {
  var element = findFormField(label);
  while (element) {
    if(element.parentNode)
    {
      element = element.parentNode;
      if (element.tagName && element.className && element.tagName == 
'DIV' && element.className == 'widget')
        return element;
    }
  }
}

function findFormField(label) {
  var name = label.htmlFor;
  var field = label.form[name];
  // Multiple fields with the same name, such as radiobuttons
  if (field) {
    if (field.length)
      field = field[0];
    return field; //znalazl i wszytsko jest OK
  }
  // No field with the exact name; find one that starts with the name
  for (var i = 0; field = label.form[i++];) {
    if (field.name && field.name.substr(0, name.length) == name)
      return field;
  }
}
// -->
</script>
</code>

If I can comment a little:
a) as I've read somewhere, it's better to get 'class' atribute directly 
rather than by getAttribute method, and it seems to help in my case,
b) checking if some attribute's value is not null prevents, I think, 
problems in IE.

Cheers!

/Ramok


More information about the Zope3-dev mailing list