Widgets API reference

class morf.widgets.Checkbox(*args, **kwargs)
configure(fieldname, raw, value, choices=None, required=True)

TODO: support required attribute on checkboxes

class morf.widgets.CheckboxGroup(*args, **kwargs)

Use this widget for groups of checkboxes. See the documentation for RadioGroup for information on how to customize the rendering of this widget.

configure(fieldname, raw, value, choices, required)

TODO: support required attribute on checkbox group

selected_decider(*, selected='checked', comparator=<built-in function contains>)

Return a function returning the string ‘selected’ whenever a value contained in current is passed to it.

class morf.widgets.ChoiceMapper

Map from object choice values to strings and back again

choice_map(choices)

Return a mapping from key values as generated by indexed_choices back to the original choice value objects

indexed_choices(choices)

Return an iterator over the list of choices annotated with the key to use as the value attribute in the widget

class morf.widgets.ColorInput(**kwargs)
class morf.widgets.DateInput(**kwargs)
class morf.widgets.DatetimeInput(**kwargs)
class morf.widgets.EmailInput(**kwargs)
class morf.widgets.HiddenInput(**kwargs)
class morf.widgets.HiddenJSON(**kwargs)

A <input type=”hidden” /> field with a JSON encoded value.

decoder

alias of json.decoder.JSONDecoder

encoder

alias of json.encoder.JSONEncoder

class morf.widgets.IndexChoiceMapper

A ChoiceMapper implementation that adds a integer index based key to map to and from choice values

choice_map(choices)

Return a mapping from choice indices to values

indexed_choices(choices, counter=None)

Return an iterator over the list of choices annotated with the key to use as the value attribute in the widget

class morf.widgets.JSONChoiceMapper

A ChoiceMapper implementation that encodes values as JSON strings

choice_map(choices)

Return a mapping from key values as generated by indexed_choices back to the original choice value objects

indexed_choices(choices)

Return an iterator over the list of choices annotated with the key to use as the value attribute in the widget

class morf.widgets.LabelFirstMultiWidget

Render a MultiWidget as a sequence of label elements, labels preceding widgets:

<label>option 1 <input .../></label>
<label>option 2 <input .../></label>
class morf.widgets.MonthInput(**kwargs)
class morf.widgets.MultiWidgetRenderingStrategy

Base rendering strategy for MultiWidgets

class morf.widgets.MultipleChoiceWidget(*args, **kwargs)

Extends the selection to multiple values

currentselection()

Return the set of currently selected indices

class morf.widgets.NumberInput(**kwargs)
class morf.widgets.PasswordInput(**kwargs)

An HTML password input

class morf.widgets.RadioGroup(*args, **kwargs)

Use this widget for radio buttons to chose between items:

color = fields.Str(choices=['red', 'yellow'],
                widget=widgets.RadioGroup())

Variants exist to render the input controls in different HTML markup structures:

  • RadioGroup.label_first() - render each option with the label preceding the input control

  • RadioGroup.as_table() - render options inside an HTML table

  • RadioGroup.as_ul() - render options as an HTML unordered list

If you need to customize radio group rendering, you can do so by creating a custom subclass of MultiWidgetRenderingStrategy

selected_decider(*, selected='checked', comparator=<built-in function eq>)

Return a function returning the string ‘selected’ the first time (and only the first time) that a value matching current is passed into it.

class morf.widgets.RangeInput(**kwargs)
class morf.widgets.SearchInput(**kwargs)
class morf.widgets.Select(*args, **kwargs)
selected_decider(*, selected='selected', comparator=<built-in function eq>)

Return a function returning the string ‘selected’ the first time (and only the first time) that a value matching current is passed into it.

class morf.widgets.SelectMulti(*args, **kwargs)
selected_decider(*, selected='checked', comparator=<built-in function contains>)

Return a function returning the string ‘selected’ whenever a value contained in current is passed to it.

class morf.widgets.SingleChoiceWidget(*args, **kwargs)

A widget with a fixed list of choices

class morf.widgets.TableMultiWidget

Render a MultiWidget as a table:

<table>
    <tbody>
        <tr>
            <td><input .../></td>
            <td><label>option 1</label></td>
        </tr>
    </tbody>
</table>
class morf.widgets.TelInput(**kwargs)
class morf.widgets.TextInput(**kwargs)

An HTML text input

class morf.widgets.Textarea(**kwargs)
class morf.widgets.TimeInput(**kwargs)
class morf.widgets.ULMultiWidget

Render a MultiWidget as an unordered list:

<ul>
    <li><label>option 1 <input .../></label></li>
    <li><label>option 2 <input .../></label></li>
</ul>
class morf.widgets.UrlInput(**kwargs)
class morf.widgets.WeekInput(**kwargs)
class morf.widgets.Widget(**kwargs)

Renders a HTML form control widget.

attrs: Dict

HTML attributes to add to the input element

choices = None

The choice of values allowable for input

copy()

Return a copy of the Widget.

All top-level attributes are independently copied.

default_attrs: FrozenSet[Tuple[str, str]] = frozenset({})

Default set of attributes for this widget

field_value = None

The original bound value, or the user’s input converted into the destination type. Named field_value so as not to clash with an <input> widget’s value attribute.

fieldname = None

The fully qualified fieldname used for the widget.

is_visible = True

Whether this widget generates user-visible output

raw = None

The raw input value. This can be either the raw value converted from the bound object or the input direct from the user when redisplaying a form with validation errors

class morf.widgets.WidgetFirstMultWidget

Render a MultiWidget as a sequence of label elements, widgets preceding labels:

<input .../><label> option 1</label>
<input .../><label> option 2</label>