[Zope3-dev] browser widgets: items widgets and label tags

yuppie y.2006_ at wcm-solutions.de
Thu Nov 9 17:06:30 EST 2006


Hi!


I plan to do some bugfixing in zope.formlib and zope.app.form. This is 
what I'd like to fix first:

The HTML label tag is not used correctly with items widgets. The result 
is invalid HTML. This is how a MultiCheckBoxWidget is basically rendered::

   <label for="WIDGET_NAME">WIDGET_LABEL</label>
   <div class="value">
     <input id="WIDGET_NAME.0" name="WIDGET_NAME"
            value="spam" type="checkbox">&nbsp;spam
     <br>
     <input id="WIDGET_NAME.1" name="WIDGET_NAME"
            value="ham" type="checkbox">&nbsp;ham
     <br>
     <input id="WIDGET_NAME.2" name="WIDGET_NAME"
            value="eggs" type="checkbox">&nbsp;eggs
   </div>

The 'for' attribute is invalid because its value is the *name* of the 
widget, not an ID of an input field.

Pointing the label to a specific input field would not be very useful. 
AFAICS the widget's label tag should have no 'for' attribute at all. 
Instead, each value text should be a label. Something like this::

   <label>WIDGET_LABEL</label>
   <div class="value">
     <label><input id="WIDGET_NAME.0" name="WIDGET_NAME"
            value="spam" type="checkbox">&nbsp;spam</label>
     <br>
     <label><input id="WIDGET_NAME.1" name="WIDGET_NAME"
            value="ham" type="checkbox">&nbsp;ham</label>
     <br>
     <label><input id="WIDGET_NAME.2" name="WIDGET_NAME"
            value="eggs" type="checkbox">&nbsp;eggs</label>
   </div>

The widget's label tag is created by the form template, not by the 
widget. ISimpleInputWidget doesn't seem to have an attribute that is 
useful for creating a label tag. zope.formlib uses IWidget's name 
attribute, but as the example above shows it is not always useful.

So I propose to add a 'controlID' attribute (or something similar)::

     controlID = TextLine(
         title=u'Control ID',
         description=u'ID used for binding the widget label.',
         required=False)

In most cases this would have the same value as 'name', but for 
MultiCheckBoxWidget and other item widgets this could be set to None or 
the ID of a specific control element.


Does that make sense? Am I missing something?

This is a bugfix, but also a significant change. Is it fine to fix this 
on the Zope 3.2 and 3.3 branches?


Cheers,

	Yuppie



More information about the Zope3-dev mailing list