Consider a simple example form:
class SampleForm(forms.Form):
name = forms.CharField()
Calling as_table() will print out an instance of this form like so:
<tr><th><label for="id_name">Name:</label></th><td><input type="text"
name="name" id="id_name" /></td></tr>
This is pretty good as table-based forms go, and passes the biggest
test for form markup in that it associates the input with the label
correctly by using the "for" attribute. But it could be better. For
example (whitespace added to make it easier to read):
<tr>
<th id="header_id_name"><label for="id_name">Name:</label></th>
<td headers="header_id_name"><input type="text" name="name"
id="id_name" /></td>
</tr>
The "headers" attribute is definitely one of the more obscure HTML
attributes, but it does serve a useful purpose (and WCAG 1.0
recommends its use) in allowing a table cell to be associated with the
specific header cells it "belongs" to.
Another possible improvement would be -- since we're outputting XHTML
here -- to also include the wrapping <tbody></tbody> around the
output, since the 'tbody' element is not implied in XHTML (though
we're not providing the wrapping <table></table>, or the wrapping
<ul></ul> in as_list(), which seems weird).
Anyone have strong opinions against this before I whip up a patch?
--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."
+1 on adding "headers", -1 on adding <tbody> (for the same reason we
leave <table> out).
Jacob
Not providing top level element is useful. It allows user to set
whatever attributes on it at a small cost of typing one tag.
-1 on <tbody> for the same reason.
As for "headers," I'm +0.
Adrian
--
Adrian Holovaty
holovaty.com | djangoproject.com
> On 4/2/07, Jacob Kaplan-Moss <jacob.kaplanm...@gmail.com> wrote:
>
> > On 4/1/07, James Bennett <ubernost...@gmail.com> wrote:
> > > Anyone have strong opinions against this before I whip up a patch?
>
> > +1 on adding "headers", -1 on adding <tbody> (for the same reason we
> > leave <table> out).
>
> -1 on <tbody> for the same reason.
>
> As for "headers," I'm +0.
I'm -0 on the "headers" idea, as it makes the HTML bulkier. On the
other hand I guess WCAG compliance is a good thing.
Jason