On Oct 31, 6:36 am, dhtml wrote:
Richard Cornford wrote:
>dhtml wrote:
>>RobG wrote:
On Oct 26, 4:38 pm, dhtml wrote:
I have written an article "Unsafe Names for HTML Form
Controls".
<snip>
>>I did not agree with all of your feedback though.
>You probably won't agree with mine either, but we will have
to wait as it will be a while before i have time to write
them all down.
I'll try to get to these comments over the weekend.
As it looks like it will be unlikely that I will have time to write
them before Monday it will be interesting to see how you do that.
><snip>
>>>In the section “What kind of Collection is a Form”, I have
serious reservations about calling a form a collection. It
isn’t, it a DOM object with certain properties. You can't
access the controls as form[i], whereas you can use
form.elements[i] because its elements property really is
a collection.
>>It's right in the spec.
>No it is not.
spec says it is:
No it dosn't.
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-40002357
| The FORM element encompasses behavior similar to a collection
| and an element.
Being a collection would be a recognisable absolute state, while being
similar to a collection is at best ambiguous. Having a - length -
property that dynamically reflects the number of form controls
contained in a form is being similar, not having any form control
retrieval methods represents not being the same as a collection.
And we can see that a form control can be referenced right off
the form:-
document.forms[0][0]
Yes, but as a product of facilitating back-compatibility rather than
as a result of the W2C DOM specification.
If something has behavior of a collection,
The DOM specification does not provide it with the behaviour of a
collection, just some (one) of the properties of a collection.
then it can be called a collection.
The representations of FORM Element in web browsers certainly can be
called 'collections', but that is because there were collections
before there was a W3C DOM standard for them.
Not an "HTMLCollection" but some sort of collection that is
vaguely described by the spec.
Specifications are not in the business of vaguely describing things.
If they don't specify something then it is not part of the
specification, and the form elements are not specified as having any
form control retrieval methods.
of course that's not the only thing a form is. It's also an
EventTarget in most modern browsers.
Except IE (7 and 8 reasonably qualify as 'modern', as 'modern' only
suggest chronological criteria (most lists of "modern" browsers
includes IE 6, but excludes the much more recent Opera 7)).
><snip>
>>>“The FORM...provides direct access to the contained input
elements”
<snip>
>>The DOM specification says that a form encompasses behavior
of a collection.
>You are reading more into the text than it actually says. In
the spec, the ECMAScript bindings documents make assertions
about the mapping of bracket notation property accessors to
collection interface methods. No such assertions are made
about the HTMLFormElement interface, and it also has no
methods that could be mapped to the property accessors. Thus
there is no DOM specified behaviour for - formElement[0]
- or - formElement['someName'] -.
You seem to interpret that as the property accessors map to
either item or namedItem method.
That is what the ECMAScript bindings say they must do for the
HTMLCollection interface.
But we can see that when using a string as a
property, the indexed element is returned.
The initial nature of the value of the expression used in a bracket
notation property accessor is irrelevant as they are always type-
converted into strings in property accessor algorithm. The ECMAScript
bindings for the DOM don't get any say in that, they can only suggest
that (like the Array [[Put]] method) some action is taken based on the
value (characters in) of that string.
>>That is a true statement. Named properties are accessed by name.
Indexed properties, by index. That's two types of ways
to index a form control.
>But neither are defined in the (ECMAScript bindings for) the
specification.
I really don't think I'm reading more into the spec. This is what it says:-
| Functions of objects that implement the HTMLCollection interface:
|
| item(index)
| This *function* returns an object that implements the Node
| interface.
| The index parameter is a Number.
| Note: This *object* can also be dereferenced using square
| bracket notation (e.g. obj[1]). Dereferencing with an integer
| index is equivalent to invoking the item function with that
| index.
| namedItem(name)
| This function returns an object that implements the Node
| interface.
| The name parameter is a String.
| Note: This object can also be dereferenced using square
| bracket notation (e.g. obj["foo"]). Dereferencing using a string
| index is equivalent to invoking the namedItem function with that
| index.
Where the spec says "Note: This *object* can also be dereferenced
using square bracket notation (e.g. obj[1])", that does define how
property accessors work on a form,
No it does not. That section is (as it clearly sates) is about the
HTMLCollection interface. At no point in the spec does it say that
object implementing the HTMLFormElement interface also implement the
HTMLCollection interface. So, as I have already pointed out, the
HTMLFormElement interface has no methods for form control retrieval
and no mapping of those methods to bracket notation property accessors
(obviously without the former the latter would not be possible).
even though they defined it wrong.
The square bracket property accessors do not do type checking.
Not on native objects and not when used on DOM elements. The
Expression is converted to a string.
<snip>
And the example shows that
document.forms[0]["0"] is the same as document.forms[0][0];
As the ECMAScript specification requires it to be.
There is no equivalent of "namedItem" being called. It doesn't
work that way.
How it works does not influence the meaning of the specification. If
accessing form controls by indexing the objects implementing the
HTMLFormElement interface were specified there would have to be method
in the interface to do that retrieval, and a mapping of property
accessors to those method in the ECMAScript bindings. These things
are absent from the specification, and so the ability to reference
form controls as properties of implementing the HTMLFormElement
interface is not specified.
It is not what can be done that is being disputed here, but only
whether the ability to do it is specified; it is not.
>>Second, a map, such as NamedNodeMap, can be a collection.
Not all collections are indexed.
<snip>
>That would depend on how you defined a collection (the DOM
specification doesn't).
Right.
>The term 'collection', in this context, comes from early
Netscape browser documentation, and was also adopted by
Microsoft to describe corresponding structures/objects.
The HTML DOM formalises (most of) those 'collection' objects
as the HTMLCollection interface, but a NamedNodeMap is not
an HTMLCollection.
Right. Its a collection in the general sense. For example, a
java.util.Map is part of the "Collections Framework". Granted,
we're not talking about Java, but in the general sense of the
word "collection" a map fits the description.
We can talk about Java in this context because the HTML DOM Java
bindings are also pertinent when considering intentions regarding the
HTMLFormElement interface. Java has no equivalent of bracket notation
property accessors so when it accesses a collection it has to use
methods. The Java bindings for HTMLCollection have those methods (as
do NodeList, etc.), but the bindings for HTMLFormElement do not. It is
hardly reasonable to assert that a specification framed in IDL and
provided with bindings for ECMAScript and Java should only be
referring only to ECMAScript implementations when saying "encompasses
behaviour similar to a collection", and as an interpretation of that
text that suggests the HTMLFormElement be a collection is contradicted
by the omissions in the Java bindings (in addition to the ECMAScript
bindings) it becomes necessary to read the text as having another
intended meaning.
Ricahrd.