[Zope3-Users] Allowing an "other" value in choice fields sourced
from vocabularies.
Gary Poster
gary at zope.com
Thu Aug 4 13:20:31 EDT 2005
On Aug 4, 2005, at 12:58 PM, Alec Munro wrote:
> Hi List,
>
> We want to allow a choice field with an "other" option, that allows
> them to type in an arbitrary value. So far, we have this working up
> until the point of validation. At the point of validation, it notices
> that the other value is not in the vocabulary, and raises
> ConstraintNotSatisfied.
> My initial thought is to create a new field type for
> "SuggestedChoice", that simply doesn't perform the checking against
> the vocabulary values. Has anyone else run up against this?
I've been threatening to release a "union" field and widget for quite
some time now. In your use case, it would work something like this
(example is taken from doc string, actually):
... cartoon_character = Union((
... schema.Choice(
... title=u'Disney',
... description=u'Some tried-and-true Disney
characters',
... values=(u'Goofy',u'Mickey',u'Donald',u'Minnie')),
... schema.TextLine(
... title=u'Write-in',
... description=u'Name your own!')),
... required=True,
... title=u'Cartoon Character',
... description=u'Your favorite cartoon character')
The widget gets the widgets for the two sub-fields and puts radio
buttons next to them. Validation is tried for all sub fields. It
works well (for this and other use cases) and is convenient.
I'm actually at the point that I might be able to put them in the
sandbox today or tomorrow, and will do so. They still need to be
cleaned up a bit :-(. I plan to write a proposal for them to be
included in 3.2 soon.
Gary
More information about the Zope3-users
mailing list