[Zope3-Users] Allowing an "other" value in choice fields sourced
from vocabularies.
Gary Poster
gary at zope.com
Thu Aug 4 13:23:50 EDT 2005
On Aug 4, 2005, at 1:19 PM, Fred Drake wrote:
> On 8/4/05, Alec Munro <alecmunro at gmail.com> wrote:
>
>> 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 haven't dealt with this, but have a bit of a suggestion as to an
> approach you can take. The details will vary depending on whether you
> want the added values to be shared across all instances or only be
> available on a per-object basis.
>
> You'll need to use a named vocabulary, so the factory will take the
> context object as an argument. This allows you to construct the
> vocabulary based on the common values plus the values added. A custom
> widget for your vocabulary would be responsible for managing the added
> values.
>
> If the added values should be specific only to a particular content
> object, you can use an annotation to store added values, or simply
> decide that values present on the object are already considered valid
> (since you allowed them at some point), and maintain anything added
> but not applied yet within the form fields.
Just to highlight: note that this part can only currently work with
vocabularies, as opposed to sources, since sources don't have access
to context.
...
Gary
More information about the Zope3-users
mailing list