[whatwg] repetition model

Hallvord Reiar Michaelsen Steen hallvors at online.no
Fri Jun 25 13:51:23 PDT 2004

On 25 Jun 2004 at 11:01, Avi Bryant wrote:

> > I do agree that the [id] stuff is somewhat dodgy. I really am at a loss of
> > how to do a better solution, though. And it does work quite well.
> In other words: it's a useful hack.  No argument there, as long as we
> agree that it would be nice to find something that *isn't* dodgy.

This complexity seems to be introduced simply because one wants to 
choose where in a "name" or "id" value the index goes. Here are some 
ideas that might make the repetition model simpler to use (at least 
for authors with simple needs): 

Introduce a mode where the browser automatically appends the new 
repetition block's index to any "name", "id" and "template" 
properties in its child elements.

For example, instead of this:

     <tr repeat="template" id="row">
      <td><input type="text" name="name_[row]" value=""></td>
      <td><input type="text" name="count_[row]" value="1"></td>
      <td><button type="remove">Delete Row</button></td>

the author might specify this to get exactly the same effect:

     <tr repeat="template" id="row" autoname="autoname">
      <td><input type="text" name="name_" value=""></td>
      <td><input type="text" name="count_" value="1"></td>
      <td><button type="remove">Delete Row</button></td>

An "autoname" attribute set to "autoname" causes the browser to add 
the index to element names automatically. It could be set to a value 
autoname="pattern" to indicate [id] replacements or the equivalent 
(more below), and the value autoname="none" to indicate that element 
names should not be changed at all (authors might want this where the 
server is capable of making sense of the order items are submitted 

This would IMO making the repetition model much more usable for 
authors. There are two problems with this approach that mean the [id] 
hack is still necessary:

1) Authors that need to control where the index goes to create names 
like row0.item or row[0]item would still have to use [id].
2) I think nested templates will be a problem. Even if both "id" and 
"template" attributes have indexes auto-appended there is nothing 
that would distinguish the index of the parent repetition block from 
the index of the nested one. 
To go with the "nested repetition" example in the spec there would be 
no way of telling whether

<input name="planetmoon135"/>

was the 35th moon of the 1st planet or the 5th moon of the 13th 

Perhaps these problems could be solved by an "indexposition" 
attribute that with a regexp specified where the index should be 

Still looking at the spec's nested repetition block template - would 
something like this work?

<li repeat="template" id="planets" autoname="pattern" 
     <label> Name: <input name="planet.name" required="required"/> 
     <h3> Moons </h3>

	<li repeat="template" id="planet.moons"  autoname="pattern" 
       <input name="planet.moon.moons"/>

The UA will deduce the index of the new repetition block as given in 
the spec, and then instead of step 7 in the "add" part go through all 
attributes and insert the index into the attribute at the end of the 
regexp match.

Hallvord Reiar Michaelsen Steen
hallvors at online.no / www.hallvord.com

More information about the whatwg mailing list