[Dojo-checkins] [dojo] #8991: dojo.attr() doesn't return current value of a text input field
dojo
trac at dojotoolkit.org
Fri Jun 19 16:31:59 EDT 2009
#8991: dojo.attr() doesn't return current value of a text input field
--------------------+-------------------------------------------------------
Reporter: roman2 | Owner: elazutkin
Type: defect | Status: reopened
Priority: normal | Milestone: 1.4
Component: HTML | Version: 1.3.0rc2
Severity: normal | Resolution:
Keywords: |
--------------------+-------------------------------------------------------
Comment(by elazutkin):
== Brain dump ==
Every DOM node has a list of attributes (attribute nodes), which
correspond to attributes in the HTML markup, and a list of properties,
which are node-specific values available directly on the node.
Attributes are manipulated by {{{getAttribute()}}}, {{{setAttribute()}}},
and {{{removeAttribute()}}}. If attribute is missing, {{{null}}} is
returned by {{{getAttribute()}}}.
Alternative interface includes {{{attributes}}} collection, and
{{{getAttributeNode()}}}. The latter returns an object with three
properties:
1. {{{name}}} --- read-only attribute name.
2. {{{specified}}} --- read-only Boolean flag.
3. {{{value}}} --- read/write attribute's value.
So any attribute can be missing, or present. In the latter case it has a
value, which is a string of some sort. If an attribute was not specified
but it has a default value per spec, it will be present with a value, but
not specified.
Properties are always present, if they are allowed for a certain type of
node. Their value type is defined by the DOM spec.
When a node is rendered, browsers takes into account both properties and
attributes. It is possible to have a property and an attribute of the same
name and for the same logical entity. According to the DOM spec properties
are final authorities on the effective value of such entity.
=== Complications ===
It all sounds nice but different browsers exhibit different behavior:
* Some properties shadow attributes, and vice versa. It is quite possible
that an attribute is missing, yet the corresponding property is readable
returning a default value. And an assignment to such property can create
the corresponding attribute too.
* Some corresponding properties and attributes may have totally different
values. Example: {{{disabled}}} the property operates with Boolean values,
while {{{disabled}}} the attribute uses strings with values
{{{"disabled"}}} for {{{true}}} and {{{""}}} for {{{false}}}.
* It is possible to have an attribute node present, yet its
{{{specified}}} property is {{{false}}}. Example: for {{{<input
type="text">}}} IE produces an attribute with {{{specified === false}}},
and this value can be changed only once.
* It is possible to have both property and attribute out of sync with
different values. The worst offender is IE.
* Removing an attribute node in same cases leaves the corresponding
property value unchanged --- needs more investigation.
* Some default values are different on different browsers. Example: non-
existent {{{tabIndex}}} is 0 on IE, and -1 on other browsers (depending on
a node type). According to the spec it cannot be negative.
* Some properties and attributes are in use, yet there is no spec for
them. Example: innerHTML.
Additional problem arises from the fact that browsers can be lax with
enforcing upper/lower case for attribute names. Some browsers tolerate any
case, some browsers require a certain camelCase as per spec. Example:
{{{tabIndex}}} on IE.
=== dojo.hasAttr() ===
The current version of {{{dojo.hasAttr()}}} checks for the presence of an
attribute node. If it is not present, or its property {{{specified}}} is
{{{false}}}, the function returns a falsy value, otherwise it returns a
truthy value.
The negative result does not mean that there is no effective value. It
does not mean that there is no property with the same name. And on IE it
does not mean that the attribute in question was not specified in the HTML
markup.
=== dojo.attr() ===
The current version of {{{dojo.attr()}}} in the "set" mode does following
actions:
1. Special processing for {{{style}}}.
2. Special processing for {{{innerHTML}}}.
3. If the value is a function, setting of an event handler is assumed,
and specially processed.
4. If the value is Boolean, it forces setting a property, rather than an
attribute.
5. If the name is in the special list, it forces a property setting.
6. Otherwise {{{setAttribute()}}} is used.
In the "get" mode it does following actions:
1. If the name is in the special list, and the existing value of a
property is not {{{undefined}}}, the property value is returned.
2. If a value of the property is Boolean or a function, it is immediately
returned.
3. If {{{dojo.hasAttr()}}} is positive, {{{getAttribute()}}'s value is
returned.
4. Otherwise {{{null}}} is returned.
To be continued...
--
Ticket URL: <http://trac.dojotoolkit.org/ticket/8991#comment:15>
dojo <http://dojotoolkit.org/>
The Dojo UI Toolkit
More information about the Dojo-checkins
mailing list