preventDefault() doesn't block keystrokes in textboxes

VERIFIED DUPLICATE of bug 54035

Status

()

Core
DOM: Events
VERIFIED DUPLICATE of bug 54035
16 years ago
16 years ago

People

(Reporter: Nicholas Zakas, Assigned: joki (gone))

Tracking

Trunk
x86
All
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

16 years ago
Build 0.9.8

When assigning an event handler for onkeypress, calling event.preventDefault() 
doesn't prevent the action to the textbox.

For example, this works:

<input type="text" onkeypress="return false">

But if done like this:

document.forms[0].txtTest.addEventListener("keypress", doKeyPress, true);

function doKeyPress(evt) {
  evt.preventDefault();
}

The characters are able to get through without any trouble. This prevents 
masking of data as it comes in when using the DOM method of assigning an event 
listener. Same problem occurs when doing the following:

document.forms[0].txtTest.onkeypress = doKeyPress;

Comment 1

16 years ago
Confirming 2002021708

What I see, is that first the typed character is inserted in
the text box, THEN the event handler is called. e.preventDefault is
called but it's too late.

DOM2 Event spec says (1.2.4):
"Some events are specified as cancelable. For these events, the DOM
implementation generally has a default action associated with the event. An
example of this is a hyperlink in a web browser. When the user clicks on the
hyperlink the default action is generally to active that hyperlink. BEFORE
PROCESSING THESE EVENTS, the implementation must check for event listeners
registered to receive the event and dispatch the event to those listeners."

DOM2 doesn' define key events but DOM3 does and keypress IS cancelable

Definitively a bug, for me.

Will attach a testcase

Comment 2

16 years ago
Created attachment 70336 [details]
testcase
(Assignee)

Comment 3

16 years ago

*** This bug has been marked as a duplicate of 54035 ***
Status: UNCONFIRMED → RESOLVED
Last Resolved: 16 years ago
Resolution: --- → DUPLICATE

Comment 4

16 years ago
verifying
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.