[Zope3-dev] small proposed widget change

Gary Poster gary at zope.com
Thu Sep 25 15:55:28 EDT 2003


I would like to add an "error" method to IBrowserWidget, as described 
below.  The purpose is to be able to avoid using the "row" method, and 
use "label", "__call__", and the new "error" to render widgets in page 
templates.


class IBrowserWidget(IWidget):
     """A field widget contains all the properties that are required
        to represent a field. Properties include css_sheet,
        default value and so on.
     """

     def __call__():
         """Render the widget
         """

     def hidden():
         """Render the widget as a hidden field
         """

     def label():
         """Render a label tag"""

     def error():
         """Render the validation error for the widget, or return
         an empty string if no error"""

     def row():
         """Render the widget as two or three div elements,
            for the label, the field and possibly the validation error

         For example:
           <div class="label">label</div><div class="field">field</div>
           <div class="error">Validation error message</div>
         """

This means that the non-interface "error" attribute will be renamed.  In 
my sandbox, this is renamed to "_error".


The implementation, in fact, is simply

     def error(self):
         if self._error:
             return zapi.getView(self._error, 'snippet', self.request)()
         return ""

and will be used within the row method, as you might expect.

Any objections?

Gary




More information about the Zope3-dev mailing list