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

NEW
Unassigned

Status

()

9 years ago
2 years ago

People

(Reporter: julien.cheritat, Unassigned)

Tracking

(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

9 years ago
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>
(Reporter)

Comment 1

9 years ago
Created attachment 464860 [details]
File used to reproduce the issue
> 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
Last Resolved: 9 years ago
Resolution: --- → INVALID
(Reporter)

Comment 3

8 years ago
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

Comment 5

5 years ago
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

Comment 6

4 years ago
Description and solution to the problem:
https://groups.google.com/forum/#!topic/mozilla.support.firefox/OSfbE-z9B9I
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

Comment 8

2 years ago
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
You need to log in before you can comment on or make changes to this bug.