Closed Bug 126437 Opened 23 years ago Closed 23 years ago

preventDefault() doesn't block keystrokes in textboxes

Categories

(Core :: DOM: Events, defect)

x86
All
defect
Not set
normal

Tracking

()

VERIFIED DUPLICATE of bug 54035

People

(Reporter: slicknet, Assigned: joki)

Details

Attachments

(1 file)

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;
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
Attached file testcase (deleted) —
*** This bug has been marked as a duplicate of 54035 ***
Status: UNCONFIRMED → RESOLVED
Closed: 23 years ago
Resolution: --- → DUPLICATE
verifying
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: