[Zope-dev] z3c.form - extraction from sequence widget

Martin Aspeli optilude at gmx.net
Thu Aug 28 15:48:21 EDT 2008


Hermann Himmelbauer wrote:
> Am Donnerstag 28 August 2008 10:14:11 schrieb Martin Aspeli:
>> Marius Gedminas wrote:
>>> On Wed, Aug 27, 2008 at 05:15:48PM -0700, Stephan Richter wrote:
>>>> On Wednesday 27 August 2008, Martin Aspeli wrote:
>>>>> This means that if the request contains the empty-marker only (no
>>>>> selection was made) for a checkbox widget (say), then the return value
>>>>> is [], rather than default (NOVALUE).
>>>>>
>>>>> Is that a bug? I have a custom checkbox widget derived from the
>>>>> standard checkbox widget, (z3c.formwidget.query, in fact), and I never
>>>>> get any "required missing" exceptions, even when I untick all the
>>>>> checkboxes and click OK.
>>>>>
>>>>> Am I missing something?
>>>> I think you have a point. Have you tried changing the behavior to
>>>> return "default" and see what tests fail? If no major failures come out
>>>> of this, I would say change it.
>>> Wait a second, maybe I'm misunderstanding this, but I certainly oppose
>>> any change that would make an unchecked checkbox an error during form
>>> validation.
>>>
>>> A required Bool field can have two values: True or False.  One is
>>> represented by a checked checkbox, the other by an unchecked checkbox.
>>> An unchecked checkbox is not missing input and should not trigger
>>> "required missing" errors.
>> What about the case when you have a list of options of which you need to
>> chose one or more? In that case, ticking none is a validation error.
> 
> Yes, in your case this should give a validation error. However, the case where 
> someone uses a checkbox for a True/False operation is at least as common. And 
> if "no ticking" gives a validation error, this would prevent using checkboxes 
> for this case. Moreover, a checkbox is typically used to represent a "Bool" 
> schema (by default it's a choice widget, I think), so that fits well, I 
> think. 
> 
> My suggestion would be to:
> 
> - Create some schema field, e.g. "MultipleChoice":
> 
> colors = MutlipleChoice(title='Colors', values=['red', 'green', 'blue'], 
> default=['green', 'blue'], required=True)
> 
> - Register a widget for this field, which is then rendered as a bunch of 
> checkboxes.

We already have such a field - it's an ICollection field with a Choice 
value_type.

I suspect that we just need widget.SequenceWidget in z3c.form to have a 
special case for len(self.terms)==1, i.e. it's a checkbox with only one 
option, or maybe a special case for a BooleanField, or indeed have 
different widgets for Boolean and ICollection fields.

Martin

-- 
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book



More information about the Zope-Dev mailing list