Elements

Elements describe the possible fields of a form; their names, structure, Python types and rules for validation. A typical schema consists of at least one container type and one or more scalar types:

from flatland import Dict, String
SearchSchema = Dict.named('search').of(String.named('keywords'))

Todo

FIXME UPDATE:

FieldSchemas are a bit like Python class definitions: they need be defined only once and don’t do much on their own. FieldSchema.create_element() produces Elements; closely related objects that hold and manipulate form data. Much like a Python class, a single FieldSchema may produce an unlimited number of Element instances.

>>> form = SearchSchema({'keywords': 'foo bar baz'})
>>> form.value
{'keywords': 'foo bar baz'}

Todo

FIXME UPDATE:

FieldSchema instances may be freely composed and shared among many containers.

>>> from flatland import List
>>> ComposedSchema = Dict.of(SearchSchema,
...                          List.named('many_searches').of(SearchSchema))
>>> form = ComposedSchema()
>>> sorted(form.value.keys())
['many_searches', 'search']

Todo

FIXME UPDATE:

Elements can be supplied to template environments and used to great effect there: elements contain all of the information needed to display or redisplay a HTML form field, including errors specific to a field.

The u, x, xa and el() members are especially useful in templates and have shortened names to help preserve your sanity when used in markup.

Element

class Element(value=Unspecified, **kw)

Base class for form fields.

A data node that stores a Python and a text value plus added state.

Instance Attributes

parent

An owning element, or None if element is topmost or not a member of a hierarchy.

valid
errors

A list of validation error messages.

warnings

A list of validation warning messages.

Members