[whatwg] Two propositions for the autofocus attribute

Markus Ernst derernst at gmx.ch
Fri Apr 16 05:24:46 PDT 2010


Am 16.04.2010 09:30 schrieb Kit Grose:
> On 16/04/2010, at 5:06 PM, Markus Ernst wrote:
> 
>> Is it not possible to say the autofocus attribute is readonly? It dose 
>> IMO not make sense to apply it via scripting, as focus() is available 
>> for scripting.
> 
> What if the form is received via XHR as HTML and simply injected to the page using innerHTML?

What would you say about this:
- multiple autofocused elements per page are valid, but only one per form
- the actual effect, as suggested before, is restricted to the page 
loading process and to the first element with the autofocus attribute

Like this, if you write an application that relies on forms received by 
XHR, and if you don't know the form structure at authoring time, it is 
not difficult to add a function that, after the form is inserted, looks 
for an element with autofocus and focus()es it at runtime.

> I admit I don't know of any other read-only HTML attributes to test the standard behaviour under those conditions.
> 
> A more similar outcome to this might be how browsers cope with adding an additional <input type="radio" name="foo" checked/> element to a form with another radio button named accordingly. A cursory glance shows that WebKit checks the new input and unchecks the previous selection, even if the user had previously made a selection.

I was thinking about checked (resp. defaultChecked) too, when I wrote my 
previous post. Anyway, the case is somehow different, as a change of 
checkedness is a visible change of the form values, and if it is made 
unexpectedly this is likely to be an authoring error. Unexpected focus 
changes on the other hand are a potential hassle which can even result 
in data loss or incomplete submission (if the focus changes from a 
textarea to an input element, and the user is not aware of it and hits 
enter).


More information about the whatwg mailing list