Re: Form submission participation (was Re: Goals for Shadow DOM review)

On Thu, 20 Feb 2014, Jonas Sicking wrote:
> On Thu, Feb 20, 2014 at 2:51 PM, Edward O'Connor <eoconnor@apple.com> wrote:
> >
> > Yeah, I think we just say that [form.elements] is the legacy feature 
> > that only exposes built-in controls. form.getParticipants() works for 
> > me.
> 
> Agreed. [form.elements] is pretty crappy anyway in that it's live and 
> that it doesn't include <input type=image> elements for webcompat 
> reasons (stemming from an old Netscape bug :))

I actually think form.elements is more important than form submission, as 
far as custom form controls go.

Pages with custom form controls are highly likely, I would guess, to be 
interactive apps that don't have any unscripted form submission. I would 
expect lots of XHR, WebSockets, and the like. However, scripts are hugely 
simplified by form.elements. Instead of having to grab things by ID, you 
can just name them, for example. This is even more true for event handlers 
on form controls, which have the form in the scope chain. For example, one 
of the big reasons for adding <output> was that it makes it easier to 
update text -- instead of:

  oninput="document.getElementById('a').textContent = process(value)"

...you can write:

  oninput="a.value = process(value)"

More concretely:

  <p><output name=o1>00:00</output> – <output name=o2>24:00</output></p>
  <input type=range min=0 max=24 value=0,24 step=1.0
         oninput="o1.value = valueLow + ':00'; o2.value = valueHigh + ':00'">

...or:

  <form onsubmit="return false" oninput="o.value = a.valueAsNumber + 
                                                   b.valueAsNumber">
   <input name=a type=number step=any> +
   <input name=b type=number step=any> =
   <output name=o for="a b"></output>
  </form>


Similarly, in a script block you can get form controls by name from forms 
gotten by name:

   document.forms.main.elements.result.value = 'Hello World';

   document.forms.npc.elements.char.value = getRandomName();

This gives you a much more intuitive way of figuring out what's going on. 
You can tell what form the controls are from, and the name just fits into 
the code without appearing to involve string manipulation, the way that 
getElementById() or querySelector() would.

(The last four examples above are all from the HTML spec.)

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Friday, 21 February 2014 19:05:16 UTC