Form Configuration with Schema Hints using Directives

Dexterity uses the directives in plone.autoform and plone.supermodel package to configure its z3c.form-based add and edit forms. A directive annotates a schema with “form hints”, which are used to configure the form when it gets generated from the schema.

The easiest way to apply form hints in Python code is to use the directives from plone.autoform and plone.supermodel. For the directives to work, the schema must derive from plone.supermodel.model.Schema.

Directives can be placed anywhere in the class body (annotations are made directly on the class). By convention they are kept next to the fields they apply to.

For example, here is a schema that omits a field:

from plone.autoform import directives
from plone.supermodel import model
from zope import schema


class ISampleSchema(model.Schema):

    title = schema.TextLine(title=u'Title')

    directives.omitted('additionalInfo')
    additionalInfo = schema.Bytes()

The form directives are taking parameters in the form of a list of field names, or a set of field name/value pairs as keyword arguments. Each directive can be used zero or more times.

There are two kinds of directives:

  • appearance related directives

  • security related directives