Implements interfaces: zope.interface.common.mapping.IEnumerableMapping, zope.interface.common.mapping.IItemMapping, zope.interface.common.mapping.IIterableMapping, zope.interface.common.mapping.IReadMapping

Data Form.

There are two similarly named properties of forms. The formType is the the so-called type of the form, and is set as the 'type' attribute on the form's root element.

The Field Standardization specification in XEP-0068, defines a way to provide a context for the field names used in this form, by setting a special hidden field named 'FORM_TYPE', to put the names of all other fields in the namespace of the value of that field. This namespace is recorded in the formNamespace instance variable.

A Form also acts as read-only dictionary, with the values of fields keyed by their name. See __getitem__.

Instance Variable formType Type of form. One of 'form', 'submit', {'cancel'}, or {'result'}. (type: str)
Instance Variable title Natural language title of the form. (type: unicode)
Instance Variable instructions Natural language instructions as a list of unicode strings without line breaks. (type: list)
Instance Variable formNamespace The optional namespace of the field names for this form. This goes in the special field named 'FORM_TYPE', if set. (type: str)
Instance Variable fields Dictionary of named fields. Note that this is meant to be used for reading, only. One should use addField or makeFields and removeField for adding and removing fields. (type: dict)
Instance Variable fieldList List of all fields, in the order they are added. Like fields, this is meant to be used for reading, only. (type: list)
Method __init__ Undocumented
Method __repr__ Undocumented
Method addField Add a field to this form.
Method removeField Remove a field from this form.
Method makeFields Create fields from values and add them to this form.
Method toElement Return the DOM representation of this Form.
Static Method fromElement Undocumented
Method __iter__ Undocumented
Method __len__ Undocumented
Method __getitem__ Called to implement evaluation of self[key].
Method get Undocumented
Method __contains__ Undocumented
Method iterkeys Undocumented
Method itervalues Undocumented
Method iteritems Undocumented
Method keys Undocumented
Method values Undocumented
Method items Undocumented
Method getValues Extract values from the named form fields.
Method typeCheck Check values of fields according to the field definition.
Static Method _parse_title Undocumented
Static Method _parse_instructions Undocumented
Static Method _parse_field Undocumented
formType =
Type of form. One of 'form', 'submit', {'cancel'}, or {'result'}. (type: str)
title =
Natural language title of the form. (type: unicode)
instructions =
Natural language instructions as a list of unicode strings without line breaks. (type: list)
formNamespace =
The optional namespace of the field names for this form. This goes in the special field named 'FORM_TYPE', if set. (type: str)
fields =
Dictionary of named fields. Note that this is meant to be used for reading, only. One should use addField or makeFields and removeField for adding and removing fields. (type: dict)
fieldList =
List of all fields, in the order they are added. Like fields, this is meant to be used for reading, only. (type: list)
def __init__(self, formType, title=None, instructions=None, formNamespace=None, fields=None): (source)
Undocumented
def __repr__(self): (source)
Undocumented
def addField(self, field): (source)

Add a field to this form.

Fields are added in order, and fields is a dictionary of the named fields, that is kept in sync only if this method is used for adding new fields. Multiple fields with the same name are disallowed.

def removeField(self, field): (source)

Remove a field from this form.

def makeFields(self, values, fieldDefs=None, filterUnknown=True): (source)

Create fields from values and add them to this form.

This creates fields from a mapping of name to value(s) and adds them to this form. It is typically used for generating outgoing forms.

If fieldDefs is not None, this is used to fill in additional properties of fields, like the field types, labels and possible options.

If filterUnknown is True and fieldDefs is not None, fields will only be created from values with a corresponding entry in fieldDefs.

If the field type is unknown, the field type is None. When the form is rendered using toElement, these fields will have no 'type' attribute, and it is up to the receiving party to interpret the values properly (e.g. by knowing about the FORM_TYPE in formNamespace and the field name).

ParametersvaluesValues to create fields from. (type: dict)
fieldDefsField definitions as a dictionary. See wokkel.iwokkel.IPubSubService.getConfigurationOptions (type: dict)
filterUnknownIf True, ignore fields that are not in fieldDefs. (type: bool)
def toElement(self): (source)

Return the DOM representation of this Form.

Returns (type: domish.Element)
@staticmethod
def _parse_title(form, element): (source)
Undocumented
@staticmethod
def _parse_instructions(form, element): (source)
Undocumented
@staticmethod
def _parse_field(form, element): (source)
Undocumented
@staticmethod
def fromElement(element): (source)
Undocumented
def __iter__(self): (source)
Undocumented
def __len__(self): (source)
Undocumented
def __getitem__(self, key): (source)

Called to implement evaluation of self[key].

This returns the value of the field with the name in key. For multi-value fields, the value is a list, otherwise a single value.

If a field has no type, and the field has multiple values, the value of the list of values. Otherwise, it will be a single value.

Raises KeyError if there is no field with the name in key.

def get(self, key, default=None): (source)
Undocumented
def __contains__(self, key): (source)
Undocumented
def iterkeys(self): (source)
Undocumented
def itervalues(self): (source)
Undocumented
def iteritems(self): (source)
Undocumented
def keys(self): (source)
Undocumented
def values(self): (source)
Undocumented
def items(self): (source)
Undocumented
def getValues(self): (source)

Extract values from the named form fields.

For all named fields, the corresponding value or values are returned in a dictionary keyed by the field name. This is equivalent do dict(f), where f is a Form.

Returns (type: dict)
See Also__getitem__
def typeCheck(self, fieldDefs=None, filterUnknown=False): (source)

Check values of fields according to the field definition.

This method walks all named fields to check their values against their type, and is typically used for forms received from other entities. The field definition in fieldDefs is used to check the field type.

If filterUnknown is True, fields that are not present in fieldDefs are removed from the form.

If the field type is None (when not set by the sending entity), the type from the field definitition is used, or 'text-single' if that is not set.

If fieldDefs is None, an empty dictionary is assumed. This is useful for coercing boolean and JID values on forms with type 'form'.

ParametersfieldDefsField definitions as a dictionary. See wokkel.iwokkel.IPubSubService.getConfigurationOptions (type: dict)
filterUnknownIf True, remove fields that are not in fieldDefs. (type: bool)
API Documentation for wokkel, generated by pydoctor at 2018-12-06 14:45:46.