Logo Search packages:      
Sourcecode: zine version File versions  Download package

zine::utils::forms::Widget Class Reference

Inheritance diagram for zine::utils::forms::Widget:

zine::utils::forms::_Renderable zine::utils::forms::Checkbox zine::utils::forms::Input zine::utils::forms::InternalWidget zine::utils::forms::ListWidget zine::utils::forms::MappingWidget zine::utils::forms::SelectBox zine::utils::forms::Textarea

List of all members.

Detailed Description

Baseclass for all widgets.  All widgets share a common interface
that can be used from within templates.

Take this form as an example:

>>> class LoginForm(Form):
...     username = TextField(required=True)
...     password = TextField(widget=PasswordInput)
...     flags = MultiChoiceField(choices=[1, 2, 3])
>>> form = LoginForm()
>>> form.validate({'username': '', 'password': '',
...                'flags': [1, 3]})
>>> widget = form.as_widget()

You can get the subwidgets by using the normal indexing operators:

>>> username = widget['username']
>>> password = widget['password']

To render a widget you can usually invoke the `render()` method.  All
keyword parameters are used as HTML attribute in the resulting tag.
You can also call the widget itself (``username()`` instead of
``username.render()``) which does the same if there are no errors for
the field but adds the default error list after the widget if there
are errors.

Widgets have some public attributes:


    gives the list of errors:

    >>> username.errors
    [u'This field is required.']

    This error list is printable:

    >>> print username.errors()
    <ul class="errors"><li>This field is required.</li></ul>

    Like any other sequence that yields list items it provides
    `as_ul` and `as_ol` methods:

    >>> print username.errors.as_ul()
    <ul><li>This field is required.</li></ul>

    Keep in mind that ``widget.errors()`` is equivalent to
    ``widget.errors.as_ul(class_='errors', hide_empty=True)``.


    returns the value of the widget as primitive.  For basic
    widgets this is always a string, for widgets with subwidgets or
    widgets with multiple values a dict or a list:

    >>> username.value
    >>> widget['flags'].value
    [u'1', u'3']

`name` gives you the name of the field for form submissions:

    >>> username.name

    Please keep in mind that the name is not always that obvious.  Zine
    supports nested form fields so it's a good idea to always use the
    name attribute.


    gives you the default domain for the widget.  This is either none
    if there is no idea for the field or `f_` + the field name with
    underscores instead of dots:

    >>> username.id


    like `errors` but also contains the errors of child

Definition at line 295 of file forms.py.

Public Member Functions

def __call__
def __call__
def __init__
def all_errors
def as_dd
def errors
def help_text
def hidden
def id
def label
def localname
def render
def value

Public Attributes


Static Public Attributes

 disable_dt = False

Private Member Functions

def _attr_setdefault

Private Attributes


The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index