[html5] r2670 - [giow] (2) Redefine how the enumeration works on <form> to be more compatible wi [...]

whatwg at whatwg.org whatwg at whatwg.org
Wed Jan 14 16:58:14 PST 2009


Author: ianh
Date: 2009-01-14 16:58:13 -0800 (Wed, 14 Jan 2009)
New Revision: 2670

Modified:
   index
   source
Log:
[giow] (2) Redefine how the enumeration works on <form> to be more compatible with content.

Modified: index
===================================================================
--- index	2009-01-14 22:05:49 UTC (rev 2669)
+++ index	2009-01-15 00:58:13 UTC (rev 2670)
@@ -22,7 +22,7 @@
   <div class=head>
    <p><a class=logo href=http://www.whatwg.org/ rel=home><img alt=WHATWG src=/images/logo></a></p>
    <h1>HTML 5</h1>
-   <h2 class="no-num no-toc" id=draft-recommendation-—-date:-01-jan-1901>Draft Recommendation — 14 January 2009</h2>
+   <h2 class="no-num no-toc" id=draft-recommendation-—-date:-01-jan-1901>Draft Recommendation — 15 January 2009</h2>
    <p>You can take part in this work. <a href=http://www.whatwg.org/mailing-list>Join the working group's discussion list.</a></p>
    <p><strong>Web designers!</strong> We have a <a href=http://blog.whatwg.org/faq/>FAQ</a>, a <a href=http://forums.whatwg.org/>forum</a>, and a <a href=http://www.whatwg.org/mailing-list#help>help mailing list</a> for you!</p>
    <dl><dt>Multiple-page version:</dt>
@@ -5395,21 +5395,21 @@
   of the values of all the <code title=attr-id><a href=#the-id-attribute>id</a></code> and <code title=attr-fe-name><a href=#attr-fe-name>name</a></code> attributes of all the elements
   <a href=#represented-by-the-collection>represented by the collection</a>.</p>
 
-  <p>The <dfn id=dom-htmlformcontrolscollection-nameditem title=dom-HTMLFormControlsCollection-namedItem><code>namedItem(<var title="">key</var>)</code></dfn>
-  method must act according to the following algorithm:
+  <p>The <dfn id=dom-htmlformcontrolscollection-nameditem title=dom-HTMLFormControlsCollection-namedItem><code>namedItem(<var title="">name</var>)</code></dfn> method must act according to the
+  following algorithm:
 
   <ol><li>If, at the time the method is called, there is exactly one node
-   in the collection that has either an <code title=attr-id><a href=#the-id-attribute>id</a></code> attribute or a <code title=attr-fe-name><a href=#attr-fe-name>name</a></code> attribute equal to <var title="">key</var>, then return that node and stop the
+   in the collection that has either an <code title=attr-id><a href=#the-id-attribute>id</a></code> attribute or a <code title=attr-fe-name><a href=#attr-fe-name>name</a></code> attribute equal to <var title="">name</var>, then return that node and stop the
    algorithm.</li>
 
    <li>Otherwise, if there are no nodes in the collection that have
-   either an <code title=attr-id><a href=#the-id-attribute>id</a></code> attribute or a <code title=attr-fe-name><a href=#attr-fe-name>name</a></code> attribute equal to <var title="">key</var>, then return null and stop the algorithm.</li>
+   either an <code title=attr-id><a href=#the-id-attribute>id</a></code> attribute or a <code title=attr-fe-name><a href=#attr-fe-name>name</a></code> attribute equal to <var title="">name</var>, then return null and stop the algorithm.</li>
 
    <!-- XXX should we return an HTMLCollection instead, like IE? -->
    <li>Otherwise, create a <code>NodeList</code> object representing a
    live view of the <code><a href=#htmlformcontrolscollection-0>HTMLFormControlsCollection</a></code> object,
    further filtered so that the only nodes in the
-   <code>NodeList</code> object are those that have either an <code title=attr-id><a href=#the-id-attribute>id</a></code> attribute or a <code title=attr-fe-name><a href=#attr-fe-name>name</a></code> attribute equal to <var title="">key</var>. The nodes in the <code>NodeList</code> object
+   <code>NodeList</code> object are those that have either an <code title=attr-id><a href=#the-id-attribute>id</a></code> attribute or a <code title=attr-fe-name><a href=#attr-fe-name>name</a></code> attribute equal to <var title="">name</var>. The nodes in the <code>NodeList</code> object
    must be sorted in <a href=#tree-order>tree order</a>.</li>
 
    <li>Return that <code>NodeList</code> object.</li>
@@ -5468,15 +5468,15 @@
   of the values of all the <code title=attr-id><a href=#the-id-attribute>id</a></code> and <code title=attr-option-name>name</code> attributes of all the elements
   <a href=#represented-by-the-collection>represented by the collection</a>.</p>
 
-  <p>The <dfn id=dom-htmloptionscollection-nameditem title=dom-HTMLOptionsCollection-namedItem><code>namedItem(<var title="">key</var>)</code></dfn>
-  method must act according to the following algorithm:
+  <p>The <dfn id=dom-htmloptionscollection-nameditem title=dom-HTMLOptionsCollection-namedItem><code>namedItem(<var title="">name</var>)</code></dfn> method must act according to the
+  following algorithm:
 
   <ol><li>If, at the time the method is called, there is exactly one node
-   in the collection that has either an <code title=attr-id><a href=#the-id-attribute>id</a></code> attribute or a <code title=attr-option-name>name</code> attribute equal to <var title="">key</var>, then return that node and stop the
+   in the collection that has either an <code title=attr-id><a href=#the-id-attribute>id</a></code> attribute or a <code title=attr-option-name>name</code> attribute equal to <var title="">name</var>, then return that node and stop the
    algorithm.</li>
 
    <li>Otherwise, if there are no nodes in the collection that have
-   either an <code title=attr-id><a href=#the-id-attribute>id</a></code> attribute or a <code title=attr-option-name>name</code> attribute equal to <var title="">key</var>, then return null and stop the algorithm.</li>
+   either an <code title=attr-id><a href=#the-id-attribute>id</a></code> attribute or a <code title=attr-option-name>name</code> attribute equal to <var title="">name</var>, then return null and stop the algorithm.</li>
 
    <!-- XXX should we return an HTMLCollection instead, like IE? -->
    <li>Otherwise, create a <code>NodeList</code> object representing a
@@ -5484,7 +5484,7 @@
    filtered so that the only nodes in the <code>NodeList</code> object
    are those that have either an <code title=attr-id><a href=#the-id-attribute>id</a></code>
    attribute or a <code title=attr-option-name>name</code> attribute
-   equal to <var title="">key</var>. The nodes in the
+   equal to <var title="">name</var>. The nodes in the
    <code>NodeList</code> object must be sorted in <a href=#tree-order>tree
    order</a>.</li>
 
@@ -23865,27 +23865,85 @@
   for historical reasons, be excluded from this particular
   collection.</p>
 
-  <p>The <code title=dom-form-elements><a href=#dom-form-elements>elements</a></code> collection is
-  also mirrored on the <code><a href=#htmlformelement>HTMLFormElement</a></code> object. The <dfn id=dom-form-length title=dom-form-length><code>length</code></dfn> DOM attribute must
-  return the number of nodes <a href=#represented-by-the-collection title="represented by the
-  collection">represented</a> by the <code title=dom-form-elements><a href=#dom-form-elements>elements</a></code> collection. The
+  <hr><p>The <dfn id=dom-form-length title=dom-form-length><code>length</code></dfn> DOM
+  attribute must return the number of nodes <a href=#represented-by-the-collection title="represented
+  by the collection">represented</a> by the <code title=dom-form-elements><a href=#dom-form-elements>elements</a></code> collection.</p>
+
+  <p>The
   <span>indices of the supported indexed properties</span> at any
   instant are the indicies supported by the object returned by the
   <code title=dom-form-elements><a href=#dom-form-elements>elements</a></code> attribute at that
-  instant. The <span>names
-  of the supported named properties</span> at any instant are the
-  names supported by the object returned by the <code title=dom-form-elements><a href=#dom-form-elements>elements</a></code> attribute at that
   instant.</p>
 
   <p>The <dfn id=dom-form-item title=dom-form-item><code>item(<var title="">index</var>)</code></dfn> method must return the value
   returned by the method of the same name on the <code title=dom-form-elements><a href=#dom-form-elements>elements</a></code> collection, when invoked
   with the same argument.</p>
 
-  <p>The <dfn id=dom-form-nameditem title=dom-form-namedItem><code>namedItem(<var title="">index</var>)</code></dfn> method must return the value
-  returned by the method of the same name on the <code title=dom-form-elements><a href=#dom-form-elements>elements</a></code> collection, when invoked
-  with the same argument.</p>
+  <p>Each <code><a href=#the-form-element>form</a></code> element has a mapping of names to elements
+  called the <dfn id=past-names-map>past names map</dfn>. It is used to persist names of
+  controls even when they change names.</p>
 
-  <p>The <dfn id=dom-form-submit title=dom-form-submit><code>submit()</code></dfn>
+  <p>The <span>names of the supported named properties</span> are the
+  union of the names currently supported by the object returned by the
+  <code title=dom-form-elements><a href=#dom-form-elements>elements</a></code> attribute, and the
+  names currently in the <a href=#past-names-map>past names map</a>.</p>
+
+  <p>The <dfn id=dom-form-nameditem title=dom-form-namedItem><code>namedItem(<var title="">name</var>)</code></dfn> method, when called, must run the
+  following steps:</p>
+
+  <ol><li>
+
+    <p>If <var title="">name</var> is one of the <span>names of the
+    supported named properties</span> of the object returned by the
+    <code title=dom-form-elements><a href=#dom-form-elements>elements</a></code> attribute, then
+    run these substeps:</p>
+
+    <ol><li><p>Let <var title="">candidate</var> be the object returned
+     by the <code title=dom-HTMLFormControlsCollection-namedItem><a href=#dom-htmlformcontrolscollection-nameditem>namedItem()</a></code>
+     method on the object returned by the <code title=dom-form-elements><a href=#dom-form-elements>elements</a></code> attribute when passed
+     the <var title="">name</var> argument.</li>
+
+     <li><p>If <var title="">candidate</var> is an element, then add a
+     mapping from <var title="">name</var> to <var title="">candidate</var> in the <code><a href=#the-form-element>form</a></code> element's
+     <a href=#past-names-map>past names map</a>, replacing the previous entry with
+     the same name, if any.</li>
+
+     <li><p>Return <var title="">candidate</var> and abort these
+     steps.</li>
+
+    </ol></li>
+
+   <li><p>Otherwise, <var title="">name</var> is the name of one of
+   the entries in the <code><a href=#the-form-element>form</a></code> element's <a href=#past-names-map>past names
+   map</a>: return the object associated with <var title="">name</var> in that map.</li>
+
+  </ol><p>If an element listed in the <code><a href=#the-form-element>form</a></code> element's <a href=#past-names-map>past
+  names map</a> is removed from the <code>Document</code>, then its
+  entries must be removed from the map.</p>
+
+  <!--
+    This ridiculous setup is intended to do as much of the right thing
+    while still supporting code written to work in IE7. IE versions
+    prior to IE8 do not update the names on the <form> element
+    collection to match new names when elements are renamed, and there
+    are enough pages that rename elements and then access them by
+    their old name that we have to support this.
+
+    But we still want to expose them using the new names, so as far as
+    possible we pretend the legacy names aren't there except if
+    there's no other element actually named that way.
+
+    Removing the element did remove the legacy name in IE7:
+    http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E...%3Cform%20action%3D%22%2F%22%3E%3Cinput%20name%3Dsubmit%3E%3C%2Fform%3E%0A%3Cscript%3E%0A%20w(document.forms%5B0%5D.submit)%3B%0A%20w(document.forms%5B0%5D.removeChild(document.getElementsByTagName('input')%5B0%5D))%3B%0A%20w(document.forms%5B0%5D.length)%3B%0A%20try%20%7B%20document.forms%5B0%5D.submit()%3B%20%7D%20catch%20(e)%20%20%7B%20w(e.message)%20%7D%0A%3C%2Fscript%3E
+
+    There's no interop on what happens when the name was originally a
+    duplicate name, so we don't persist such accesses - at the time
+    of writing, Safari returned the first element, Firefox returned
+    null (as we do), and IE7 returned the original collection:
+    http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E...%3Cform%20action%3D%22%2F%22%3E%3Cinput%20name%3Da%20id%3Dfirst%3E%3Cinput%20name%3Da%20id%3Dsecond%3E%3C%2Fform%3E%0A%3Cscript%3E%0A%20w%28document.forms[0].a%29%3B%0A%20document.getElementsByTagName%28%27input%27%29[0].name%20%3D%20%27b%27%3B%0A%20document.getElementsByTagName%28%27input%27%29[1].name%20%3D%20%27b%27%3B%0A%20w%28document.forms[0].length%29%3B%0A%20w%28document.forms[0].a.id%29%3B%0A%3C%2Fscript%3E
+  -->
+
+  <hr><p>The <dfn id=dom-form-submit title=dom-form-submit><code>submit()</code></dfn>
   method, when invoked, must <a href=#concept-form-submit title=concept-form-submit>submit</a> the <code><a href=#the-form-element>form</a></code>
   element from the <code><a href=#the-form-element>form</a></code> element itself.</p>
 
@@ -28328,7 +28386,7 @@
   returned by the method of the same name on the <code title=dom-select-options><a href=#dom-select-options>options</a></code> collection, when invoked
   with the same argument.</p>
 
-  <p>The <dfn id=dom-select-nameditem title=dom-select-namedItem><code>namedItem(<var title="">index</var>)</code></dfn> method must return the value
+  <p>The <dfn id=dom-select-nameditem title=dom-select-namedItem><code>namedItem(<var title="">name</var>)</code></dfn> method must return the value
   returned by the method of the same name on the <code title=dom-select-options><a href=#dom-select-options>options</a></code> collection, when invoked
   with the same argument.</p>
 

Modified: source
===================================================================
--- source	2009-01-14 22:05:49 UTC (rev 2669)
+++ source	2009-01-15 00:58:13 UTC (rev 2670)
@@ -5246,8 +5246,9 @@
   <span>represented by the collection</span>.</p>
 
   <p>The <dfn
-  title="dom-HTMLFormControlsCollection-namedItem"><code>namedItem(<var title="">key</var>)</code></dfn>
-  method must act according to the following algorithm:
+  title="dom-HTMLFormControlsCollection-namedItem"><code>namedItem(<var
+  title="">name</var>)</code></dfn> method must act according to the
+  following algorithm:
 
   <ol>
 
@@ -5255,13 +5256,13 @@
    in the collection that has either an <code
    title="attr-id">id</code> attribute or a <code
    title="attr-fe-name">name</code> attribute equal to <var
-   title="">key</var>, then return that node and stop the
+   title="">name</var>, then return that node and stop the
    algorithm.</li>
 
    <li>Otherwise, if there are no nodes in the collection that have
    either an <code title="attr-id">id</code> attribute or a <code
    title="attr-fe-name">name</code> attribute equal to <var
-   title="">key</var>, then return null and stop the algorithm.</li>
+   title="">name</var>, then return null and stop the algorithm.</li>
 
    <!-- XXX should we return an HTMLCollection instead, like IE? -->
    <li>Otherwise, create a <code>NodeList</code> object representing a
@@ -5270,7 +5271,7 @@
    <code>NodeList</code> object are those that have either an <code
    title="attr-id">id</code> attribute or a <code
    title="attr-fe-name">name</code> attribute equal to <var
-   title="">key</var>. The nodes in the <code>NodeList</code> object
+   title="">name</var>. The nodes in the <code>NodeList</code> object
    must be sorted in <span>tree order</span>.</li>
 
    <li>Return that <code>NodeList</code> object.</li>
@@ -5343,8 +5344,9 @@
   <span>represented by the collection</span>.</p>
 
   <p>The <dfn
-  title="dom-HTMLOptionsCollection-namedItem"><code>namedItem(<var title="">key</var>)</code></dfn>
-  method must act according to the following algorithm:
+  title="dom-HTMLOptionsCollection-namedItem"><code>namedItem(<var
+  title="">name</var>)</code></dfn> method must act according to the
+  following algorithm:
 
   <ol>
 
@@ -5352,13 +5354,13 @@
    in the collection that has either an <code
    title="attr-id">id</code> attribute or a <code
    title="attr-option-name">name</code> attribute equal to <var
-   title="">key</var>, then return that node and stop the
+   title="">name</var>, then return that node and stop the
    algorithm.</li>
 
    <li>Otherwise, if there are no nodes in the collection that have
    either an <code title="attr-id">id</code> attribute or a <code
    title="attr-option-name">name</code> attribute equal to <var
-   title="">key</var>, then return null and stop the algorithm.</li>
+   title="">name</var>, then return null and stop the algorithm.</li>
 
    <!-- XXX should we return an HTMLCollection instead, like IE? -->
    <li>Otherwise, create a <code>NodeList</code> object representing a
@@ -5366,7 +5368,7 @@
    filtered so that the only nodes in the <code>NodeList</code> object
    are those that have either an <code title="attr-id">id</code>
    attribute or a <code title="attr-option-name">name</code> attribute
-   equal to <var title="">key</var>. The nodes in the
+   equal to <var title="">name</var>. The nodes in the
    <code>NodeList</code> object must be sorted in <span>tree
    order</span>.</li>
 
@@ -26559,19 +26561,17 @@
   for historical reasons, be excluded from this particular
   collection.</p>
 
-  <p>The <code title="dom-form-elements">elements</code> collection is
-  also mirrored on the <code>HTMLFormElement</code> object. The <dfn
-  title="dom-form-length"><code>length</code></dfn> DOM attribute must
-  return the number of nodes <span title="represented by the
-  collection">represented</span> by the <code
-  title="dom-form-elements">elements</code> collection. The
+  <hr>
+
+  <p>The <dfn title="dom-form-length"><code>length</code></dfn> DOM
+  attribute must return the number of nodes <span title="represented
+  by the collection">represented</span> by the <code
+  title="dom-form-elements">elements</code> collection.</p>
+
+  <p>The
   <span>indices of the supported indexed properties</span> at any
   instant are the indicies supported by the object returned by the
   <code title="dom-form-elements">elements</code> attribute at that
-  instant. The <span>names
-  of the supported named properties</span> at any instant are the
-  names supported by the object returned by the <code
-  title="dom-form-elements">elements</code> attribute at that
   instant.</p>
 
   <p>The <dfn title="dom-form-item"><code>item(<var
@@ -26580,12 +26580,85 @@
   title="dom-form-elements">elements</code> collection, when invoked
   with the same argument.</p>
 
+  <p>Each <code>form</code> element has a mapping of names to elements
+  called the <dfn>past names map</dfn>. It is used to persist names of
+  controls even when they change names.</p>
+
+  <p>The <span>names of the supported named properties</span> are the
+  union of the names currently supported by the object returned by the
+  <code title="dom-form-elements">elements</code> attribute, and the
+  names currently in the <span>past names map</span>.</p>
+
   <p>The <dfn title="dom-form-namedItem"><code>namedItem(<var
-  title="">index</var>)</code></dfn> method must return the value
-  returned by the method of the same name on the <code
-  title="dom-form-elements">elements</code> collection, when invoked
-  with the same argument.</p>
+  title="">name</var>)</code></dfn> method, when called, must run the
+  following steps:</p>
 
+  <ol>
+
+   <li>
+
+    <p>If <var title="">name</var> is one of the <span>names of the
+    supported named properties</span> of the object returned by the
+    <code title="dom-form-elements">elements</code> attribute, then
+    run these substeps:</p>
+
+    <ol>
+
+     <li><p>Let <var title="">candidate</var> be the object returned
+     by the <code
+     title="dom-HTMLFormControlsCollection-namedItem">namedItem()</code>
+     method on the object returned by the <code
+     title="dom-form-elements">elements</code> attribute when passed
+     the <var title="">name</var> argument.</p></li>
+
+     <li><p>If <var title="">candidate</var> is an element, then add a
+     mapping from <var title="">name</var> to <var
+     title="">candidate</var> in the <code>form</code> element's
+     <span>past names map</span>, replacing the previous entry with
+     the same name, if any.</p></li>
+
+     <li><p>Return <var title="">candidate</var> and abort these
+     steps.</p></li>
+
+    </ol>
+
+   </li>
+
+   <li><p>Otherwise, <var title="">name</var> is the name of one of
+   the entries in the <code>form</code> element's <span>past names
+   map</span>: return the object associated with <var
+   title="">name</var> in that map.</p></li>
+
+  </ol>
+
+  <p>If an element listed in the <code>form</code> element's <span>past
+  names map</span> is removed from the <code>Document</code>, then its
+  entries must be removed from the map.</p>
+
+  <!--
+    This ridiculous setup is intended to do as much of the right thing
+    while still supporting code written to work in IE7. IE versions
+    prior to IE8 do not update the names on the <form> element
+    collection to match new names when elements are renamed, and there
+    are enough pages that rename elements and then access them by
+    their old name that we have to support this.
+
+    But we still want to expose them using the new names, so as far as
+    possible we pretend the legacy names aren't there except if
+    there's no other element actually named that way.
+
+    Removing the element did remove the legacy name in IE7:
+    http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E...%3Cform%20action%3D%22%2F%22%3E%3Cinput%20name%3Dsubmit%3E%3C%2Fform%3E%0A%3Cscript%3E%0A%20w(document.forms%5B0%5D.submit)%3B%0A%20w(document.forms%5B0%5D.removeChild(document.getElementsByTagName('input')%5B0%5D))%3B%0A%20w(document.forms%5B0%5D.length)%3B%0A%20try%20%7B%20document.forms%5B0%5D.submit()%3B%20%7D%20catch%20(e)%20%20%7B%20w(e.message)%20%7D%0A%3C%2Fscript%3E
+
+    There's no interop on what happens when the name was originally a
+    duplicate name, so we don't persist such accesses - at the time
+    of writing, Safari returned the first element, Firefox returned
+    null (as we do), and IE7 returned the original collection:
+    http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E...%3Cform%20action%3D%22%2F%22%3E%3Cinput%20name%3Da%20id%3Dfirst%3E%3Cinput%20name%3Da%20id%3Dsecond%3E%3C%2Fform%3E%0A%3Cscript%3E%0A%20w%28document.forms[0].a%29%3B%0A%20document.getElementsByTagName%28%27input%27%29[0].name%20%3D%20%27b%27%3B%0A%20document.getElementsByTagName%28%27input%27%29[1].name%20%3D%20%27b%27%3B%0A%20w%28document.forms[0].length%29%3B%0A%20w%28document.forms[0].a.id%29%3B%0A%3C%2Fscript%3E
+  -->
+
+  <hr>
+
   <p>The <dfn title="dom-form-submit"><code>submit()</code></dfn>
   method, when invoked, must <span
   title="concept-form-submit">submit</span> the <code>form</code>
@@ -31758,7 +31831,7 @@
   with the same argument.</p>
 
   <p>The <dfn title="dom-select-namedItem"><code>namedItem(<var
-  title="">index</var>)</code></dfn> method must return the value
+  title="">name</var>)</code></dfn> method must return the value
   returned by the method of the same name on the <code
   title="dom-select-options">options</code> collection, when invoked
   with the same argument.</p>




More information about the Commit-Watchers mailing list