formular.widgets - (X)HTML Widgets

These are the (X)HTML widgets used to represents fields as UI-Elements which can be used in templates to be rendered to (X)HTML.

class Renderable(dialect=None)

An object which is renderable to html or xhtml depending one the given dialect, if dialect is None dialect will be used.

builder
The builder used to create the html/xhtml.
dialect
The default dialect for instances of this class, normally "html".
render()
Returns a rendered version of this object as unicode string.
set_default_attrs(attrs)

Sets default values in the given attrs dict which will be passed to the builder upon rendering and returns it.

New in version 0.3.

class Widget(field, name, **kwargs)

Represents a field as a UI-Element.

Parameters:
as_dd()

Returns the label as dt and the rendered widget as dd.

New in version 0.2.

as_td()

Returns the rendered widget in a td.

New in version 0.2.

label
The label of the field as a Label instance.
value
The primitive value of the field.
class TextInput(field, name, **kwargs)

Represents every field which is not represented through any other widget as well as formular.fields.TextField instance for single lines.

as_li()

Returns the rendered widget in a li.

New in version 0.2.

render(**attrs)

Returns the rendered input element.

New in version 0.2: Now supports arbitary attributes for the input.

class Textarea(field, name, **kwargs)

Represents a formular.fields.TextField instance as one or more lines of text in the UI.

render(**attrs)

Returns the rendered textarea element.

New in version 0.2: Now supports arbitary attributes for the textarea.

class PasswordInput(field, name, **kwargs)

Represents a formular.fields.PasswordField instance as an UI-Element.

as_li()

Returns the rendered widget in a li.

New in version 0.2.

render(**attrs)

Returns the rendered input element.

New in version 0.2: Now supports arbitary attributes for the input.

class Checkbox(field, name, **kwargs)

Represents a formular.fields.BooleanField instance as an UI-Element.

as_li()

Returns the rendered widget in a li.

New in version 0.2.

render(**attrs)

Returns the rendered input element.

New in version 0.2: Now supports arbitary attributes for the input.

class SubmitInput(field, name, **kwargs)

Represents a formular.fields.SubmitField instance as an UI-Element.

New in version 0.2.

class RadioButtonGroup(*args, **kwargs)

Represents a formular.fields.ChoiceField instance as an UI-Element.

as_ol(**attrs)

Renders the widget as an ol.

New in version 0.2: Now supports arbitary attributes for the ul.

as_ul(**attrs)

Renders the widget as an ul.

New in version 0.2: Now supports arbitary attributes for the ul.

subwidget
alias of RadioButton
render(**attrs)

Returns the rendered ul element.

New in version 0.2: Now supports arbitary attributes for the ul.

class RadioButton(parent, value, label)

Represents a formular.fields.ChoiceField instance value as an UI-Element.

checked
True if the value for this widget is selected.
as_li()

Returns the rendered widget in a li.

New in version 0.2.

render(**attrs)
Returns the rendered input element.
class CheckboxGroup(*args, **kwargs)

Represents a formular.fields.MultiChoiceField instance as an UI-Element.

as_ol(**attrs)

Renders the widget as an ol.

New in version 0.2: Now supports arbitary attributes for the ul.

as_ul(**attrs)

Renders the widget as an ul.

New in version 0.2: Now supports arbitary attributes for the ul.

subwidget
alias of GroupCheckbox
render(**attrs)

Returns the rendered ul element.

New in version 0.2: Now supports arbitary attributes for the ul.

class GroupCheckbox(parent, value, label)

Represents a formular.fields.MultiChoiceField instance value as an UI-Element.

checked
True if the value for this widget is selected.
as_li()

Returns the rendered widget in a li.

New in version 0.2.

render(**attrs)
Returns the rendered input element.
class MappingWidget(*args, **kwargs)

Represents a formular.field.MappingWidget instance as an UI-Element and stores the widgets of the mapped fields.

as_dl(**attrs)

Renders the subwidgets as a dl.

New in version 0.2: Now supports arbitary attributes for the dl

as_tr(**attrs)

Renders the subwidgets as a tr

New in version 0.2: Now supports arbitary attributes for the tr.

render(**attrs)

Returns the rendered dl element.

New in version 0.2: Now supports arbitary attributes for the dl.

class MultipleWidget(*args, **kwargs)

Represents a formular.fields.Multiple instance as an UI-Element.

as_ol(**attrs)

Renders the widget as an ol.

New in version 0.2: Now supports arbitary attributes for the ul.

as_ul(**attrs)

Renders the widget as an ul.

New in version 0.2: Now supports arbitary attributes for the ul.

iter_subwidgets()

Yields a subwidget for every value.

New in version 0.2.

render(**attrs)

Returns the rendered ul element.

New in version 0.2: Now supports arbitary attributes for the ul

class FormWidget(form, **kwargs)

Represents a formular.forms.HTMLForm as an UI-Element.

errors
A ValidationErrorWidget instance.
render(method=u'post', **attrs)

Returns the rendered form.

Parameter:method – The method used to send the form back to the server.

Note

This method can be used as a jinja macro The caller will have to take care of the visible fields.

New in version 0.2: Accepts now arbitary attributes for the form

class ValidationErrorWidget(form, dialect=None)

Represents the validation error of a formular.forms.Form instance.

as_ol(**attrs)
Renders the validation error as an ordered list.
as_ul(**attrs)
Renders the validation error as an unordered list.
as_dl(**attrs)

Renders the validation error as a dl.

This method may raise a RuntimeError if the form has top-level errors.

render(**attrs)

Renders the validation error as a div with a h1. The errors are displayed as an ul if they cannot be displayed as a dl.

If the form has no validation errors this method returns an empty string.

class ReCAPTCHAWidget(field, name, **kwargs)

Represents a formular.fields.ReCAPTCHAField as an UI-Element.

New in version 0.2.

render()
Renders the field using the reCAPTCHA javascript api or an iframe if the browser doesn’t support javascript.

Previous topic

formular.validators - Validators

Next topic

formular.exceptions - Exceptions

This Page