Base class for browser widgets.

>>> setUp()

The class provides some basic functionality common to all browser widgets.

Browser widgets have a required attribute, which indicates whether or not the underlying field requires input. By default, the widget's required attribute is equal to the field's required attribute:

>>> from zope.schema import Field
>>> from zope.publisher.browser import TestRequest
>>> field = Field(required=True)
>>> widget = BrowserWidget(field, TestRequest())
>>> widget.required
>>> field.required = False
>>> widget = BrowserWidget(field, TestRequest())
>>> widget.required

However, the two required values are independent of one another:

>>> field.required = True
>>> widget.required

Browser widgets have an error state, which can be rendered in a form using the error() method. The error method delegates the error rendering to a view that is registered as providing IWidgetInputErrorView. To illustrate, we can create and register a simple error display view:

>>> from import IWidgetInputError
>>> class SnippetErrorView:
...     implements(IWidgetInputErrorView)
...     def __init__(self, context, request):
...         self.context = context
...     def snippet(self):
...         return "The error: " + str(self.context.errors)
>>> from import ztapi
>>> ztapi.browserViewProviding(IWidgetInputError, SnippetErrorView,
...                            IWidgetInputErrorView)

Whever an error occurs, widgets should set _error:

>>> widget._error = WidgetInputError('foo', 'Foo', ('Err1', 'Err2'))

so that it can be displayed using the error() method:

>>> widget.error()
"The error: ('Err1', 'Err2')"
>>> tearDown()

Base classes

Implemented Interfaces



Known Subclasses