Skip to content

Commit

Permalink
[giow] (2) Redefine how the enumeration works on <form> to be more co…
Browse files Browse the repository at this point in the history
…mpatible with content.

git-svn-id: http://svn.whatwg.org/webapps@2670 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information
Hixie committed Jan 15, 2009
1 parent 3a1caeb commit 78df7b2
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 48 deletions.
104 changes: 81 additions & 23 deletions index
Expand Up @@ -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-&mdash;-date:-01-jan-1901>Draft Recommendation &mdash; 14 January 2009</h2>
<h2 class="no-num no-toc" id=draft-recommendation-&mdash;-date:-01-jan-1901>Draft Recommendation &mdash; 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>
Expand Down Expand Up @@ -5395,21 +5395,21 @@ interface <dfn id=htmlformcontrolscollection-0>HTMLFormControlsCollection</dfn>
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>
Expand Down Expand Up @@ -5468,23 +5468,23 @@ interface <dfn id=htmloptionscollection-0>HTMLOptionsCollection</dfn> {
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
live view of the <code><a href=#htmloptionscollection-0>HTMLOptionsCollection</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-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>

Expand Down Expand Up @@ -23865,27 +23865,85 @@ interface <dfn id=htmlformelement>HTMLFormElement</dfn> : <a href=#htmlelement>H
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 <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
-->

<p>The <dfn id=dom-form-submit title=dom-form-submit><code>submit()</code></dfn>
<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>

Expand Down Expand Up @@ -28328,7 +28386,7 @@ interface <dfn id=htmlselectelement>HTMLSelectElement</dfn> : <a href=#htmleleme
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>

Expand Down

0 comments on commit 78df7b2

Please sign in to comment.