Opened 13 years ago
Closed 12 years ago
#6337 closed bug (fixed)
Button click within form causes submit event even though return false is there
Reported by: | margieroginski | Owned by: | dmethvin |
---|---|---|---|
Priority: | undecided | Milestone: | 1.4.3 |
Component: | event | Version: | 1.4.2 |
Keywords: | submit event return false | Cc: | |
Blocked by: | Blocking: |
Description
I have a small test case below where I create a button inside a form and set its onclick hander to my js function, show_input(), followed by a "return false", like this:
Immediately following that is a one line script that clicks the button.
<button id="testbutton1" onclick="show_input(); return false;"> Test </button> <script type="text/javascript"> $('#testbutton1').click(); </script>
In jquery 1.3.2, when the .click() occurs, it calls show_input() and no submit event occurs aftwards, due to the return false. But in in Jquery 1.4.2, it calls show_input() and then the submit event fires (it does a GET), as if the return false is not there.
If I manually click the button, I do not see the submit event, so this seems to be somehow related to the click being inline.
Here is the exact html that can be used to replicate it.
<html> <head> <script src="/site_media/js/jquery-1.3.2.js" type="text/javascript"></script> <script type="text/javascript"> function show_input() { console.log("hello, world"); } </script> </head> <body> <div id="container"> <form> <div class="taskform_row_description form-row"> <button id="testbutton1" onclick="show_input(); return false;"> Test </button> <script type="text/javascript"> $('#testbutton1').click(); </script> </div> </form> </div> </body> </html>
This seems to me to be a bug since it is very incompatible with previous behavior...
Thanks, Margie
Change History (4)
comment:1 Changed 13 years ago by
Component: | unfiled → event |
---|
comment:2 Changed 13 years ago by
Owner: | set to dmethvin |
---|
comment:3 Changed 12 years ago by
need: | Review → Commit |
---|
comment:4 Changed 12 years ago by
Priority: | → undecided |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Fixed http://github.com/jquery/jquery/commit/adff8e45e255409e8f78a3347dea01bdbee0a53d
We only need to call preventDefault in this case.
It looks like the problem is in jQuery.event.trigger; the code to run inline scripts sets event.result to false but does not stopPropagation or preventDefault. I've taken the ticket and will put together a patch.