Closed Bug 586329 Opened 14 years ago Closed 4 years ago

HTMLFormElement.submit() stops working if a submit button removes itself from the form during its click event handler

Categories

(Core :: DOM: Forms, defect, P3)

x86
Windows XP
defect

Tracking

()

RESOLVED FIXED
92 Branch
Tracking Status
firefox92 --- fixed

People

(Reporter: julien.cheritat, Assigned: edgar)

References

Details

Attachments

(2 files)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.125 Safari/533.4 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 When an <input type=submit> element removes itself during its click event, the submit() method stops working on the parent form element. Here is a small example to demonstrate this issue : Reproducible: Always Steps to Reproduce: 1.Create an HTML file with the content given below 2.Open this file in Firefox (same issue in K-meleon) 3.Click on the "remove" button 4.Click on the "JS submit" button Actual Results: Nothing happens Expected Results: The form should be submitted Html file used to reproduce : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head><title></title> <script>function c(){ document.forms[0].removeChild(document.getElementById("a3")); return false;}</script> </head> <body> <form method="get" id="test" action="http://bugzilla.mozilla.org/"> <input type="button" value="JS submit" onclick="document.forms[0].submit()" name="a1"/> <input type="submit" value="Form submit" name="a2" /> <input type="submit" value="removed" onclick="return c();" name="a3" id="a3"/> </form> </body> </html>
> The form should be submitted Why? Here's what the HTML5 spec has to say: The element's activation behavior, if the element has a form owner, is to submit the form owner from the input element; otherwise, it is to do nothing. Activation behavior is the default action, so happens after user-defined event handlers have fired. Since the event handler removes the input from the form, the input no longer has a form owner at activation time, so nothing happens. Which is exactly the behavior I see in Gecko, Webkit, and Presto.
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → INVALID
The "JS submit" button has document.forms[0].submit(), clicking on it MUST submit the form.
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
Oh, I see. I thought you meant that clicking the "removed" button was supposed to submit it. Confirming; presumably the issue is something to do with pending submissions not being cleared out when the third button is removed...
Status: UNCONFIRMED → NEW
Ever confirmed: true
This bug also affects modern platforms (tested Ubuntu Linux 13.10 and Windows 7, but it's probably platform-independent). Please update when you're able.
Blocks: 847845
Breaks google.co.jp's search page - if you select things in the autocomplete menu it doesn't submit. See https://webcompat.com/issues/1169
For anyone else looking at this, a workaround appears to be setting the button's type property to "button" - https://bugzilla.mozilla.org/show_bug.cgi?id=494755#c5
Component: HTML: Form Submission → DOM: Core & HTML
Severity: normal → S3
Component: DOM: Core & HTML → DOM: Forms
Priority: -- → P3
Assignee: nobody → echen
Attachment #9230271 - Attachment description: WIP: Bug 586329 - Clear the defer submission state when submit button is removed from the form during its click event handler; r=smaug → Bug 586329 - Clear the defer submission state when submit button is removed from the form during its click event handler; r=smaug
Status: NEW → ASSIGNED
Pushed by echen@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/2ebb071ca4b4 Clear the defer submission state when submit button is removed from the form during its click event handler; r=smaug
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/29689 for changes under testing/web-platform/tests
Status: ASSIGNED → RESOLVED
Closed: 14 years ago4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 92 Branch
Upstream PR merged by moz-wptsync-bot
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: