Closed
Bug 157568
Opened 22 years ago
Closed 11 years ago
Will not properly capture the Enter key event and stop a form from submitting.
Categories
(Core :: DOM: Events, defect)
Tracking
()
RESOLVED
WORKSFORME
People
(Reporter: pellender, Unassigned)
References
Details
(Keywords: testcase)
Attachments
(1 file)
860 bytes,
text/html
|
Details |
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; T312461)
BuildID: 2002061104
When user presses enter on a form using the provided example it is not stoping
the Enter key event when doing a 'return false;' thus causing the form to
submit anyways.
Reproducible: Always
Steps to Reproduce:
1. Load included webpage sample.
2. Type your name in the textbox and press Enter.
Actual Results: The form is submitted.
Expected Results: This works fine in all versions of IE and Most NS, but not
the latest ones... nor the latest Mozilla build... Maybe i'm just doing
something wrong but according to all documentation i've read, this should stop
the Enter key from submitting a form if your not on the submit button.
It definately calls the event handler and returns all of the right data, but it
still submits the form even tho I return false. I've also tried using the
KEYPRESS and KEYUP and tried capturing them all.
<html>
<head><title>Bug Test</title>
<script language="JavaScript"><!--
var nav = window.Event ? true : false;
if (nav) {
window.captureEvents(Event.KEYDOWN);
window.onkeydown = NetscapeEventHandler_KeyDown;
} else {
document.onkeydown = MicrosoftEventHandler_KeyDown;
}
function NetscapeEventHandler_KeyDown(e) {
if (e.which == 13 && e.target.type != 'textarea' && e.target.type !
= 'submit') { return false; }
return true;
}
function MicrosoftEventHandler_KeyDown() {
if (event.keyCode == 13 && event.srcElement.type != 'textarea' &&
event.srcElement.type != 'submit') { return false; }
return true;
}
//--></script>
</head>
<body>
<form action="test" method="post">
<input type=text name=test>
<input type=submit>
</form>
</body>
</html>
Comment 1•22 years ago
|
||
This has to do with the Enter simulating click on the submit button. After the
onkeypress the onclick event occurs which return true since it is missing and
the form is submitted. This might potentially break sites that want to prevent
submission by Enter key.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
Comment 2•22 years ago
|
||
Shouldn't that JS be cancelling keypress, not keydown? The two are not the same...
Assignee: joki → jkeiser
Paul said he tried keypress as well as keydown. I use DOM calls (like those in
bug 81739, of which this may be a duplicate), and can't prevent Enter from
submitting forms either. Even a form.onSubmit handler cannot prevent submission.
The only thing that works is a DOM-style submit event handler that uses
preventDefault() to prevent submission. Unfortunately, this works _too_ well,
and prevents the form from ever being submitted.
Comment 4•22 years ago
|
||
Bulk moving P1-P5 un-milestoned bugs to future.
Target Milestone: --- → Future
Comment 5•21 years ago
|
||
Bug 81739 is fixed. This bug is basically about the fact the cancelling keydown
does not cancel keypress/keyup. That issue is already filed (and may be
wontfix; I can't recall).
Assignee: john → events
Keywords: qawanted
Priority: P3 → --
QA Contact: vladimire → ian
Whiteboard: DUPEME
Target Milestone: Future → ---
Comment 6•20 years ago
|
||
Updated•20 years ago
|
Whiteboard: DUPEME → DUPEME, testcase
Updated•15 years ago
|
Assignee: events → nobody
QA Contact: ian → events
Comment 7•11 years ago
|
||
Windows 2000 support has been dropped a while ago. Please only reopen this bug if you can reproduce it on Windows XP or older with current Firefox builds.
Updated•11 years ago
|
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → WONTFIX
Comment 8•11 years ago
|
||
Ioana, there appears to be nothing win2k-specific about this bug. Please don't resolve bugs as wontfix based on their (bogus, automatically set by Bugzilla) OS field without actually trying to reproduce them.
Status: RESOLVED → REOPENED
Resolution: WONTFIX → ---
Comment 9•11 years ago
|
||
Comment 0 specified clearly Win2k (see user agent) and I didn't see any other OSs specified in comments, it wasn't just the OS field.
Is there a specific OS you want this tested on?
Comment 10•11 years ago
|
||
Comment 11•11 years ago
|
||
Mozilla/5.0 (Windows NT 6.1; rv:25.0) Gecko/20100101 Firefox/25.0
The test cases in bug 81739 work for the key down event the same as for key press. I'm not seeing anything submitted.
The test case in this bug causes Nightly to freeze (when the third alert is shown, or when checking the checkbox for preventing it to appear - on the second alert). Any ideas why that happens?
Flags: needinfo?(bzbarsky)
Keywords: qawanted
Comment 12•11 years ago
|
||
No idea. I can't reproduce any freezing. Presumably you took out the captureEvent call to even get the alerts?
In any case, this one worksforme.
Status: REOPENED → RESOLVED
Closed: 11 years ago → 11 years ago
Flags: needinfo?(bzbarsky)
Resolution: --- → WORKSFORME
Comment 13•11 years ago
|
||
(In reply to Boris Zbarsky (:bz) (vacation Aug 10-19) from comment #12)
> No idea. I can't reproduce any freezing. Presumably you took out the
> captureEvent call to even get the alerts?
Nope, didn't change anything in the testcase.
Comment 14•11 years ago
|
||
Oh, I guess we put the captureEvent stuff back... <sigh>.
You need to log in
before you can comment on or make changes to this bug.
Description
•