Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8617 (new defect)

Opened 1 year ago

Last modified 7 months ago

[PATCH] KeyPress event bug on IE

Reported by: greyWolf Assigned to: sam
Priority: normal Milestone: 2.x
Component: Prototype Version: edge
Severity: major Keywords: 1.6 fixedinbranch
Cc:

Description

While trying to observe keyPress event on IE, I found that prototype, don't handle properly this event observation.

When observing a "keypress" event on IE, prototype attach the "keydown" event on the element, like for Konqueror or Safari. Or this two event are not the same.

To resolve this bug, we must change functions : Event.observe and Event.stopObserving.

and replace the test

if (name == 'keypress' && 
        (navigator.appVersion.match(/Konqueror|Safari|KHTML/)
        || element.attachEvent))
      name = 'keydown';

by

if (name == 'keypress' && !(/MSIE/.test(navigator.userAgent)) && 
        (navigator.appVersion.match(/Konqueror|Safari|KHTML/)
        || element.attachEvent))
      name = 'keydown';

I would like to provide a test case for this patch but I haven't seen any test runner for events. So I am not sure how to do it properly.

So you will find attached the modified prototype.js and a html file to test the event handling.

I have tested the patch on IE and Firefox.

Note : this could breaks some code if they was making workaround to deal with the "keydown" event.

This bug is related with some entries about "event" and "keypress" on the user-mailing-list.

http://groups.google.com/group/rubyonrails-spinoffs/browse_thread/thread/5d32313a685b283a/6f6f3f11c5d93231?lnk=gst&q=event+keypress&rnum=2#6f6f3f11c5d93231

http://groups.google.com/group/rubyonrails-spinoffs/browse_thread/thread/bea61976ce0ce7e5/78002e3c999551d8?lnk=gst&q=event+keypress&rnum=3#78002e3c999551d8

http://groups.google.com/group/rubyonrails-spinoffs/browse_thread/thread/107dee29962715be/8ad6fb759da4538e?lnk=gst&q=event+keypress&rnum=8#8ad6fb759da4538e

Attachments

testEventKeyPress.html (1.7 kB) - added by greyWolf on 06/09/07 09:33:11.
Html Test Page
prototype.js (69.7 kB) - added by greyWolf on 06/09/07 09:34:26.
Modified prototype.js
prototype_1.6.0_rc0.js (124.9 kB) - added by greyWolf on 08/15/07 22:15:44.
Patched version of prototype.js 1.6.0 rc0

Change History

06/09/07 09:33:11 changed by greyWolf

  • attachment testEventKeyPress.html added.

Html Test Page

06/09/07 09:34:26 changed by greyWolf

  • attachment prototype.js added.

Modified prototype.js

06/09/07 09:38:00 changed by greyWolf

  • severity changed from normal to major.

06/09/07 10:42:10 changed by greyWolf

  • summary changed from KeyPress event bug on IE to [PATCH] KeyPress event bug on IE.

06/09/07 20:01:42 changed by greyWolf

I have made a mistake while giving the patch. I gave the patch for the version 1.5.0 of prototype.

For the current version, actually we have to replace in the Event.observe and Event.stopObserving :

if (name == 'keypress' &&
      (Prototype.Browser.WebKit || element.attachEvent))
      name = 'keydown';

by

if (name == 'keypress' && !Prototype.Browser.IE &&
      (Prototype.Browser.WebKit || element.attachEvent))
      name = 'keydown';

I hope that you have not been too confused.

06/14/07 00:37:06 changed by Tobie

  • keywords changed from event keypress ie to 1.6 fixedinbranch.

08/15/07 22:15:44 changed by greyWolf

  • attachment prototype_1.6.0_rc0.js added.

Patched version of prototype.js 1.6.0 rc0

08/15/07 22:21:08 changed by greyWolf

Hello,

Here is the patch for the version 1.6.0 rc0 of prototype.

function getDOMEventName(eventName) {
    if (!Event.DOMEvents.include(eventName)) return "dataavailable";
    var keypressDomEvtName = "keydown";
    if (Prototype.Browser.IE) {
    	keypressDomEvtName = "keypress";
    }
    
    return { keypress: keypressDomEvtName }[eventName] || eventName;
}

You will find in the attached files, the patched version of prototype 1.6.0 rc0.

10/22/07 13:31:04 changed by Tobie

Fixed in [7928]