I need to override the behavior of the widget assigned to a field on a z3c.form (specifically the widget used for a schema.Bool field like the one declared below) to change the way the widget mode works under different conditions:
from plone.autoform.interfaces import IFormFieldProvider
from plone.supermodel import model
from zope import schema
from zope.interface import provider
@provider(IFormFieldProvider)
class IGoogleNews(model.Schema):
"""Behavior interface to add some Google News features."""
standout_journalism = schema.Bool(
title=_(u'Standout Journalism'),
required=False,
)
news_keywords = schema.Tuple(
title=_(u'Keywords'),
value_type=schema.TextLine(),
required=False,
)
This is example code derived from ftw.datepicker widget.
In widget.py:
Register using zcml (configure.zcml):
Use the widget for your boolean field.
Following this approach I created several widgets, For example also a KeywordWidget
On the plus side:
malus:
The example does not include any templates, you may get them
from z3c.formor plone.z3cform.*This approach is pretty straight forward and does not use the all the components a widget usually does. Like register a widget template for every mode, etc.