2011/08/18

AddRemoveWidget and ComboBoxWidget

AddRemoveWidget permits to add self-entered data, which makes it a good replacement for KeywordWidget. Example code looks like:
from Products.AddRemoveWidget.AddRemoveWidget import AddRemoveWidget

...
atapi.LinesField(
'watershed',
storage=atapi.AnnotationStorage(),
widget=AddRemoveWidget(
label=_(u"Watershed"),
description=_(u"Enter one tag per line, multiple words allowed."),
),
vocabulary_factory='watershed',
),


AddRemoveWidget works with multiple-value fileds, if you need just single-value fields, try ComboBoxWidget instead. Example code looks like:
from Products.AddRemoveWidget.ComboBoxWidget import ComboBoxWidget

...

atapi.StringField(
'vote',
storage=atapi.AnnotationStorage(),
widget=ComboBoxWidget(
label=_(u"Best Band Ever"),
description=_(u"Single Choice."),
),
vocabulary=['The Beatles', 'The Smiths', 'Led Zeppelin', 'Joy Division'],
),


Look into the source code for more config options.

No comments: