Defect #1636

Use of Prototype's Element-methods (like this.up("form"))

Added by C G over 14 years ago. Updated over 14 years ago.

Status:ClosedStart date:2008-07-14
Priority:NormalDue date:
Assignee:-% Done:


Target version:0.8
Resolution:Fixed Affected version:


In /views/issues/_list.rhtml for example you use "this.up('form')". Actually the up-method is not available on the element itself, but only by the element, when it is returned by the $() method.

Quote from the Prototype-Documentation:

Prototype adds many convenience methods to elements returned by the $() function.

So, the correct way would be using: $(this).up('form') or Element.up(this,'form')

In IE7 the up method is actually not available on "this". In your case it's working "accidentially", because there is a call to $$('.hascontextmenu') executed somewhere in context_menu.js during page load, and by that the up-method is added to all DOM elements.

To better understand the problem check out this example (make sure to set the correct path and filename to prototype.js)

  <script src="prototype-1.5.js"></script>

  <form id='theform'>
    <a id='thea' onclick='alert($(this).up("form").id); return false;' href='#'>CLICK HERE</a>

  <script type='text/javascript'>
    // the following call to $$() is what essentially makes it work in Redmine (called from context_menu.js via unselectAll):
    $$('.hascontextmenu');  // COMMENT THIS LINE AND CLICK THE 'CLICK HERE' LINK TO SEE THE 'BUG' (in IE7)



Associated revisions

Revision 1667
Added by Jean-Philippe Lang over 14 years ago

Javascript fix (#1636).


#1 Updated by Jean-Philippe Lang over 14 years ago

  • Status changed from New to Closed
  • Target version set to 0.8
  • Resolution set to Fixed

Fixed in r1667.
Thanks for your tip.

Also available in: Atom PDF