.. -*-doctest-*-

==============
Field Schemata
==============

There are several places in the schemaeditor where we need to complete
and or improve on the schema provided by field instances in order to
fully support the field edit forms.

The schema used on an edit form for a field is retrieved by
introspecting the interfaces provided by the field looking for the
first which is or extends zope.schema.interfaces.IField.

    >>> from zope import schema
    >>> from plone.schemaeditor.browser.field import traversal, edit
    >>> field = schema.Field()
    >>> context = traversal.FieldContext(field, None)
    >>> form = edit.FieldEditForm(context, None)
    >>> form.schema
    <InterfaceClass zope.schema.interfaces.IField>

The default values for fields should generally be the same type as the
field itself.  The plone.schemaeditor declares that the zope.schema
field classes implement schemata with correct default and
missing_value types.

    >>> field = schema.Text()
    >>> context = traversal.FieldContext(field, None)
    >>> form = edit.FieldEditForm(context, None)
    >>> form.schema
    <InterfaceClass plone.schemaeditor.schema.IText>
    >>> form.schema['default']
    <zope.schema._bootstrapfields.Text object at ...>

    >>> field = schema.TextLine()
    >>> context = traversal.FieldContext(field, None)
    >>> form = edit.FieldEditForm(context, None)
    >>> form.schema
    <InterfaceClass plone.schemaeditor.schema.ITextLine>
    >>> form.schema['default']
    <zope.schema._bootstrapfields.TextLine object at ...>

    >>> field = schema.Datetime()
    >>> context = traversal.FieldContext(field, None)
    >>> form = edit.FieldEditForm(context, None)
    >>> form.schema
    <InterfaceClass plone.schemaeditor.schema.IDatetime>
    >>> form.schema['default']
    <zope.schema._field.Datetime object at ...>

The Datetime fields also have corrected min/max field types.

    >>> field = schema.Datetime()
    >>> context = traversal.FieldContext(field, None)
    >>> form = edit.FieldEditForm(context, None)
    >>> form.schema['min']
    <zope.schema._field.Datetime object at ...>
    >>> form.schema['max']
    <zope.schema._field.Datetime object at ...>

The Bool edit form omits the 'required' and 'missing_value' fields.

    >>> field = schema.Bool()
    >>> context = traversal.FieldContext(field, None)
    >>> form = edit.FieldEditForm(context, None)
    >>> 'required' in form.fields
    False
    >>> 'missing_value' in form.fields
    False
