This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 24352 - Node removal and form association by HTML Parser
Summary: Node removal and form association by HTML Parser
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-22 07:16 UTC by contributor
Modified: 2014-01-30 21:51 UTC (History)
3 users (show)

See Also:


Attachments
Test case (1.60 KB, text/html)
2014-01-22 08:43 UTC, Kent Tamura
Details

Description contributor 2014-01-22 07:16:28 UTC
Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html
Multipage: http://www.whatwg.org/C#association-of-controls-and-forms
Complete: http://www.whatwg.org/c#association-of-controls-and-forms
Referrer: 

Comment:
Node removal and form association by HTML Parser

Posted from: 122.216.99.139
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.29 Safari/537.36
Comment 1 Kent Tamura 2014-01-22 07:27:07 UTC
I filed this.

The specification says:
> When an element is removed from a Document resulting in a form-associated
> element and its form owner (if any) no longer being in the same home subtree,
> then the user agent must reset the form owner of that form-associated element.

None of IE11, Firefox 26, WebKit, and Blink follows this.

IE11 behavior:
When a form-associated element is removed from a Document, the user agent resets the its form owner.

Other browsers:
When an element is removed from its home subtree resulting in a ... (the rest is same as the spec.)


It seems IE11 wants to support non-tree association by HTML parser only in the document tree, and other browser try to support non-tree association by HTML parser in any home subtree.

Proposal: Follow IE11 behavior.


Test code:
</head>
<body>

<div id=willBeRemoved>
<div>
<form id=f1>
<input id=input-child>
<img id=img-child>
</div>
<input id=input-outer1>
<img id=img-outer1>
</div><!-- willBeRemoved -->
<input id=input-outer2>
<img id=img-outer2>

<hr >
<pre></pre>
<script>
function $(id) { return document.getElementById(id); }
function log(str) {
    var c = document.querySelector('pre');
    c.innerHTML += str + '\n';
    console.log(str);
}

var f1 = document.querySelector('#f1');
var e = f1.elements;
for (var i = 0; i < e.length; ++i) {
    log(i + ': id=' + e[i].id);
}

log('form[img-child]: ' + f1['img-child']);
log('form[img-outer1]: ' + f1['img-outer1']);
log('form[img-outer2]: ' + f1['img-outer2']);

log('*** Detach an ancestor of the form and *-outer1 ***');
document.body.removeChild($('willBeRemoved'));
for (var i = 0; i < e.length; ++i) {
    log(i + ': id=' + e[i].id);
}
log('form[img-child]: ' + f1['img-child']);
log('form[img-outer1]: ' + f1['img-outer1']);
log('form[img-outer2]: ' + f1['img-outer2']);
</script>
</body>
</html>
Comment 2 Kent Tamura 2014-01-22 08:31:27 UTC
(In reply to Kent Tamura from comment #1)
> IE11 behavior:
> When a form-associated element is removed from a Document, the user agent
> resets the its form owner.

Correction:
When a form-associated element or its form owner is removed from its home subtree, the user agent resets the form-associated element's form owner.
Comment 3 Kent Tamura 2014-01-22 08:43:18 UTC
Created attachment 1432 [details]
Test case
Comment 4 Kent Tamura 2014-01-23 00:25:59 UTC
HTMLFormElement::elements implies we keep association-by-parser only in the document tree.

http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#dom-form-elements
> The elements IDL attribute must return an HTMLFormControlsCollection rooted
> at the Document node while the form element is in a Document and rooted at
> the form element itself when it is not,

So, the IE11 behavior is reasonable.
Comment 5 Ian 'Hixie' Hickson 2014-01-27 23:20:58 UTC
I don't understand why the quote in comment 4 implies that. Can you elaborate?
Comment 6 Ian 'Hixie' Hickson 2014-01-27 23:25:24 UTC
The idea of the spec as written was that you should be able to move a section of the document to another part of the document, without breaking forms within it.

For example:
   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2776

The radio buttons keep working as a pair, unrelated to the top one, even after you click the button, meaning they're still in the form, even though the whole subtree has been moved out of the tree and back in elsewhere.
Comment 7 Kent Tamura 2014-01-28 00:16:47 UTC
(In reply to Ian 'Hixie' Hickson from comment #5)
> I don't understand why the quote in comment 4 implies that. Can you
> elaborate?

"rooted at the form element itself (when it is not in a Document)" means form.elements doesn't contain elements magically associated by HTML parser.

If the intention is to keep magical association, we should change the followings.


http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#dom-form-elements
 "rooted at form element"  -> "rooted at the root element of form's home subtree"

(in order to form.elements contains magical associated elements)


http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html
  "When an element is removed from a Document resulting in a form-associated
  element and its form owner (if any) no longer being in the same home
  subtree, ..."
 ->
  "When an element is removed from its home subtree resulting ..."

(in order to avoid to associate a form and an element in different home subtrees when a subtree not in a Document is separated into two subtrees)
Comment 8 Ian 'Hixie' Hickson 2014-01-28 20:35:55 UTC
That's a fair point, I agree that if we keep this association in the orphaned subtree case that we should do that.
Comment 9 Ian 'Hixie' Hickson 2014-01-28 21:41:47 UTC
I think we want all three of these cases to keep working, as they do in all the browsers I tested (not IE):

   http://software.hixie.ch/utilities/js/live-dom-viewer/saved/2780

This suggests that we want to go more towards the other browsers than towards IE.

Any opinions?
Comment 10 Kent Tamura 2014-01-28 23:51:55 UTC
I'm ok to go forward with the keep-magic-association-in-orphan-tree policy.
Comment 11 contributor 2014-01-30 21:51:47 UTC
Checked in as WHATWG revision r8446.
Check-in comment: Turns out browsers reset the form owner not just when a node is taken from a document, but also when it's taken from a subtree. which makes sense.
http://html5.org/tools/web-apps-tracker?from=8445&to=8446