#669 ✓invalid

Cancelling form-submit with return fails in Opera

Reported by Taco | May 1st, 2009 @ 07:32 AM | in 1.7

When catching the keydown-event in an input field and assigning a new action to it, the event.stop() fails (no error message).

To reproduce: Use this code:

<title>Event.stop(event) in Opera 9.64</title>
<script type="text/javascript" src="js/prototype-"></script>
<script type="text/javascript">
document.observe("dom:loaded", function() {
  $('variable').observe('keydown', function(event) {
    if (event.keyCode==Event.KEY_RETURN) {
  } );
} );

<form action="#">
  <input type="text" id="variable" name="variable" />

Expected result: You can type in the textfield, when you press return, nothing happens

Result in opera 9.64: When pressing return, the form gets submitted

Comments and changes to this ticket

  • Andrew Dupont

    Andrew Dupont May 2nd, 2009 @ 08:56 PM

    • State changed from “new” to “bug”
    • Milestone set to 1.7

    This might be Opera's issue to fix and not ours; I'll investigate and let you know.

  • Andrew Dupont

    Andrew Dupont May 12th, 2009 @ 06:31 AM

    • Assigned user set to “Andrew Dupont”
  • Taco

    Taco July 30th, 2009 @ 10:45 PM

    Ehm, I don't know if it's appreciated and such, but bump :)

  • Tobie Langel

    Tobie Langel July 30th, 2009 @ 11:00 PM

    It's neither appreciated nor unappreciated. Your best bet if you want this solved would be to see if and how other frameworks have handled the issue and submit a patch.

  • Diego Perini

    Diego Perini August 4th, 2009 @ 01:44 AM

    • Tag set to events, key

    Taco, you are using (and trying to stop) the wrong event (submit unrelated).

    KEYDOWN is not the event triggering the "default" submit action of the form.

    To be able to cancel that on Opera you must use the "keypress" event instead.

    This should work cross-browser but let me know if it doesn't work.

    I did some test with Opera 9.64 and seems to work for me.

  • Taco

    Taco August 4th, 2009 @ 11:01 AM

    Brilliant, that works like a charm. It behaves as expected now in IE 7, firefox 3.5.1 and of course, Opera 9.64.

    I'll file a ticket in Scriptaculous, which uses (and tries to cancel) the keydown event for the Ajax.Autocompleter.

    Thanks a lot for this!

  • Tobie Langel

    Tobie Langel August 4th, 2009 @ 01:11 PM

    • Tag changed from events, key to section:dom
    • State changed from “bug” to “invalid”
  • Tobie Langel

    Tobie Langel August 4th, 2009 @ 01:12 PM

    Thanks Diego, for your help.

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