<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>24352</bug_id>
          
          <creation_ts>2014-01-22 07:16:28 +0000</creation_ts>
          <short_desc>Node removal and form association by HTML Parser</short_desc>
          <delta_ts>2014-01-30 21:51:47 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>HTML</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#association-of-controls-and-forms</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>ian</cc>
    
    <cc>mike</cc>
    
    <cc>tkent</cc>
          
          <qa_contact>contributor</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>98865</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2014-01-22 07:16:28 +0000</bug_when>
    <thetext>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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98866</commentid>
    <comment_count>1</comment_count>
    <who name="Kent Tamura">tkent</who>
    <bug_when>2014-01-22 07:27:07 +0000</bug_when>
    <thetext>I filed this.

The specification says:
&gt; When an element is removed from a Document resulting in a form-associated
&gt; element and its form owner (if any) no longer being in the same home subtree,
&gt; 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:
&lt;/head&gt;
&lt;body&gt;

&lt;div id=willBeRemoved&gt;
&lt;div&gt;
&lt;form id=f1&gt;
&lt;input id=input-child&gt;
&lt;img id=img-child&gt;
&lt;/div&gt;
&lt;input id=input-outer1&gt;
&lt;img id=img-outer1&gt;
&lt;/div&gt;&lt;!-- willBeRemoved --&gt;
&lt;input id=input-outer2&gt;
&lt;img id=img-outer2&gt;

&lt;hr &gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;script&gt;
function $(id) { return document.getElementById(id); }
function log(str) {
    var c = document.querySelector(&apos;pre&apos;);
    c.innerHTML += str + &apos;\n&apos;;
    console.log(str);
}

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

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

log(&apos;*** Detach an ancestor of the form and *-outer1 ***&apos;);
document.body.removeChild($(&apos;willBeRemoved&apos;));
for (var i = 0; i &lt; e.length; ++i) {
    log(i + &apos;: id=&apos; + e[i].id);
}
log(&apos;form[img-child]: &apos; + f1[&apos;img-child&apos;]);
log(&apos;form[img-outer1]: &apos; + f1[&apos;img-outer1&apos;]);
log(&apos;form[img-outer2]: &apos; + f1[&apos;img-outer2&apos;]);
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98869</commentid>
    <comment_count>2</comment_count>
    <who name="Kent Tamura">tkent</who>
    <bug_when>2014-01-22 08:31:27 +0000</bug_when>
    <thetext>(In reply to Kent Tamura from comment #1)
&gt; IE11 behavior:
&gt; When a form-associated element is removed from a Document, the user agent
&gt; 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&apos;s form owner.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98872</commentid>
    <comment_count>3</comment_count>
      <attachid>1432</attachid>
    <who name="Kent Tamura">tkent</who>
    <bug_when>2014-01-22 08:43:18 +0000</bug_when>
    <thetext>Created attachment 1432
Test case</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>98916</commentid>
    <comment_count>4</comment_count>
    <who name="Kent Tamura">tkent</who>
    <bug_when>2014-01-23 00:25:59 +0000</bug_when>
    <thetext>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
&gt; The elements IDL attribute must return an HTMLFormControlsCollection rooted
&gt; at the Document node while the form element is in a Document and rooted at
&gt; the form element itself when it is not,

So, the IE11 behavior is reasonable.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99216</commentid>
    <comment_count>5</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-01-27 23:20:58 +0000</bug_when>
    <thetext>I don&apos;t understand why the quote in comment 4 implies that. Can you elaborate?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99217</commentid>
    <comment_count>6</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-01-27 23:25:24 +0000</bug_when>
    <thetext>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&apos;re still in the form, even though the whole subtree has been moved out of the tree and back in elsewhere.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99227</commentid>
    <comment_count>7</comment_count>
    <who name="Kent Tamura">tkent</who>
    <bug_when>2014-01-28 00:16:47 +0000</bug_when>
    <thetext>(In reply to Ian &apos;Hixie&apos; Hickson from comment #5)
&gt; I don&apos;t understand why the quote in comment 4 implies that. Can you
&gt; elaborate?

&quot;rooted at the form element itself (when it is not in a Document)&quot; means form.elements doesn&apos;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
 &quot;rooted at form element&quot;  -&gt; &quot;rooted at the root element of form&apos;s home subtree&quot;

(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
  &quot;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, ...&quot;
 -&gt;
  &quot;When an element is removed from its home subtree resulting ...&quot;

(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)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99354</commentid>
    <comment_count>8</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-01-28 20:35:55 +0000</bug_when>
    <thetext>That&apos;s a fair point, I agree that if we keep this association in the orphaned subtree case that we should do that.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99358</commentid>
    <comment_count>9</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2014-01-28 21:41:47 +0000</bug_when>
    <thetext>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?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99374</commentid>
    <comment_count>10</comment_count>
    <who name="Kent Tamura">tkent</who>
    <bug_when>2014-01-28 23:51:55 +0000</bug_when>
    <thetext>I&apos;m ok to go forward with the keep-magic-association-in-orphan-tree policy.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>99502</commentid>
    <comment_count>11</comment_count>
    <who name="">contributor</who>
    <bug_when>2014-01-30 21:51:47 +0000</bug_when>
    <thetext>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&apos;s taken from a subtree. which makes sense.
http://html5.org/tools/web-apps-tracker?from=8445&amp;to=8446</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>1432</attachid>
            <date>2014-01-22 08:43:18 +0000</date>
            <delta_ts>2014-01-22 08:43:18 +0000</delta_ts>
            <desc>Test case</desc>
            <filename>form-parse2.html</filename>
            <type>text/html</type>
            <size>1637</size>
            <attacher name="Kent Tamura">tkent</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgo8aGVhZD4KPG1ldGEgY2hhcnNldD11dGYtOD4KPG1ldGEg
aHR0cC1lcXVpdj0iWC1VQS1Db21wYXRpYmxlIiBjb250ZW50PSJJRT1lZGdlIj4KPC9oZWFkPgo8
Ym9keT4KCjxkaXYgaWQ9d2lsbEJlUmVtb3ZlZD4KPGRpdj4KPGZvcm0gaWQ9ZjE+CjxpbnB1dCBp
ZD1pbnB1dC1jaGlsZD4KPGltZyBpZD1pbWctY2hpbGQ+CjwvZGl2Pgo8aW5wdXQgaWQ9aW5wdXQt
b3V0ZXIxPgo8aW1nIGlkPWltZy1vdXRlcjE+CjwvZ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