Closed
Bug 81739
Opened 24 years ago
Closed 21 years ago
onKeyPress event handler can't cancel form.submit triggered by pressing Enter in text input [form sub]
Categories
(Core :: DOM: UI Events & Focus Handling, defect)
Tracking
()
RESOLVED
WORKSFORME
mozilla1.2beta
People
(Reporter: david.manz, Assigned: saari)
References
Details
(Keywords: testcase, Whiteboard: [eapp])
Attachments
(2 files)
If there is a single input type=text on a page, pressing enter in the input will
cause the form to be submitted. In both IE and Netscape 4, this can be prevented
by returning false from an onKeyPress event handler. However, this does not work
in Mozilla.
Reporter | ||
Comment 1•24 years ago
|
||
Updated•23 years ago
|
Status: UNCONFIRMED → NEW
Ever confirmed: true
Comment 2•23 years ago
|
||
onkeypress handler is handled by the form before it reaches the text box
check... looks like the form captures the return key. Even if I add this handler
to form itself the enter key submits it before reaching the handler.
The only workabout I could come up with is this:
if(keycode == 13) {
if(e.stopPropagation)
e.stopPropagation();
return false; }
}
if(document.addEventListener)
document.addEventListener("keypress",cancelSubmit,1);
Basicly capture the event at document level and not let it go any further. This
works for not submitting the form, but if there is a text area you wont be able
to go to the next line.
Comment 4•23 years ago
|
||
I could be wrong, but I think this could be generalized. If you return false
from the onKeyPress handler, the key press should not be propagated regardless
of which key was pressed. In theory, you should be able to prevent the user
from entering any given keypress, be it <Return> or the 'X' key, or whatever,
into a given control.
In Mozilla, the keypress, and hence the character, seems to be reaching the
control before the onKeyPress handler is even called, thus returning false has
no effect.
Updated•23 years ago
|
Summary: onKeyPress event handler can't cancel form.submit triggered by pressing Enter in text input → onKeyPress event handler can't cancel form.submit triggered by pressing Enter in text input [form sub]
We encountered similar problem but I think it is related so I will add a
comment here instead of opening a new but.
When we set an event handler, the handler is triggered OK when the Enter key is
pressed but the form is submitted prematurely before the handler is completed
(which means that returning 'false' from the handler will not suppress the form
posting). The same code worked very well for us on NS 4.7 .
See attachment 'Demonstrates how the form is posted before the event handler is
completed' for instructions how to reproduce it.
Comment 9•23 years ago
|
||
reassigning (forgot to check the radio first time)
Assignee: alexsavulov → joki
QA Contact: vladimire → madhur
Assignee | ||
Comment 10•23 years ago
|
||
dup of another soon to be in 0.9.9
Target Milestone: --- → mozilla0.9.9
Comment 12•23 years ago
|
||
124990 and its associated bugs is not quite ready for checkin for 0.9.9.
Maintaining high priority and moving to 1.0 for completion and further testing.
Target Milestone: mozilla0.9.9 → mozilla1.0
Updated•23 years ago
|
QA Contact: madhur → rakeshmishra
Comment 14•23 years ago
|
||
this also happens on Windows XP as well as Windows ME
Comment 15•22 years ago
|
||
Looks like we have missed the train for 1.0.1. Can we retarget this for 1.2?
Assignee | ||
Comment 16•22 years ago
|
||
the work this depends upon will be landing soon
Target Milestone: mozilla1.0 → mozilla1.2beta
Updated•22 years ago
|
QA Contact: rakeshmishra → trix
Comment 18•21 years ago
|
||
This worksforme in a current build. Also verified by code inspection that we
check whether the event was cancelled before triggering submit-on-enter.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → WORKSFORME
Updated•6 years ago
|
Component: Event Handling → User events and focus handling
You need to log in
before you can comment on or make changes to this bug.
Description
•