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

Ticket #9666 (reopened defect)

Opened 8 months ago

Last modified 2 months ago

[PATCH] Convert keydown to keypress for Safari (how 1.5+ used to do)

Reported by: russell@mile26.com Assigned to: sam
Priority: normal Milestone: 2.x
Component: Prototype Version: edge
Severity: major Keywords:
Cc:

Description

When using:

$(el).observe('keypress',fxHandler)

to have the handler check for the enter key and stop a form submit, everything works fine with Prototype 1.5.1.1 but is broken in Prototype 1.6.0_rc0. I have not been able to determine a patch as yet.

Very simple test pages illustrating the bug can be found at:

www.mile26.com/bug_prototype15.htm (works as expected) www.mile26.com/bug_prototype16.htm (BUG: cannot stop event from submitting form)

I put severity = major as this bug breaks backwards compatibility and can cause unexpected behaviors. I also do not know if there are other cases where events bubble unexpectedly.

Attachments

9666_patch.diff (467 bytes) - added by russell@mile26.com on 09/26/07 02:03:48.
Patch to return keypress eventname
event_keypress.diff (393 bytes) - added by jdalton on 03/30/08 22:14:02.
converts eventName 'keypress' -> 'keydown' for Safari

Change History

09/26/07 01:14:54 changed by adamlogic

This seems to be because Prototype is attaching a keydown observer rather than keypress. Prior to 1.6, this was only done for IE and WebKit (because of keyCode issues), but now all requests to add a keypress observer will use keydown instead. I'm not sure why this was changed.

FF apparently has some issues with stopping the <enter> key on keydown, but it works fine with keypress. Unless this gets changed back to the way it was in 1.5.1, you'll need to attach your keypress events the nasty way, which you already tested in "method 2" on your test pages.

09/26/07 02:03:48 changed by russell@mile26.com

  • attachment 9666_patch.diff added.

Patch to return keypress eventname

09/26/07 02:06:48 changed by russell@mile26.com

Thanks Adam, I figured that out as well. After testing on IE 7 and Firefox (win + mac) and Safari (mac) I decided to use the attached patch. Allowing keypress to be changed to keydown breaks this case in all browsers I tested. I don't know why keypress is changed in any scenario as it seems to be easy enough to just use keydown on your own instead if necessary.

10/17/07 14:53:35 changed by kangax

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [7928]

12/30/07 21:12:00 changed by maxkir

  • status changed from closed to reopened.
  • resolution deleted.

In my experience, code in prototype 1.5.x, which translated keypress to keydown in Safari, worked better than current. In Safari, keypress events for arrow keys contain zero keyCode and zero charCode. So I think it is better to revert to the old behaviour - convert keypress to keydown for Safari.

03/30/08 22:08:42 changed by jdalton

  • summary changed from Cannot stop keypress event from bubbling up to form in Prototype 1.6.0_rc0 (bug is not present in Protoype 1.5.1.1) to Convert keydown to keypress for Safari (how 1.5+ used to do).

03/30/08 22:12:50 changed by jdalton

  • summary changed from Convert keydown to keypress for Safari (how 1.5+ used to do) to [PATCH] Convert keydown to keypress for Safari (how 1.5+ used to do).

03/30/08 22:14:02 changed by jdalton

  • attachment event_keypress.diff added.

converts eventName 'keypress' -> 'keydown' for Safari