Stephan Richter wrote:
> On Thursday 28 August 2008, Martin Aspeli wrote:
>> 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.
> Widgets should not make these sort of decisions. I think this is the 
> responsibility of the data converter. I am pretty sure that writing more 
> specific data converters will solve our problem.

In the implementation of extract() in the SequenceWidget(), the 
extract() method does this:

     def extract(self, default=interfaces.NOVALUE):
         """See z3c.form.interfaces.IWidget."""
         if ( not in self.request and
   '-empty-marker' in self.request):
             return []
         value = self.request.get(, default)
         if value != default:
             for token in value:
                 if token == self.noValueToken:
                 except LookupError:
                     return default
         return value

It's the 'return []' that's the problem, i.e. it's treating the return 
value when empty-marker is in place as something other than the 
'default' that the base widget class will use when the field isn't in 
the request:

     def extract(self, default=interfaces.NOVALUE):
         """See z3c.form.interfaces.IWidget."""
         return self.request.get(, default)

I think to get those same semantics for sequence fields, we'll need 
something in the extract() method.

I also don't quite understand why we use [] and not NOVALUE, even when 
the field isn't required. It seems to me that the BooleanField case is 
the special case. In fact, it's somewhat weird that a BooleanField, 
which is scalar, should default to using a SequenceWidget.


Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See

Zope-Dev maillist  -
**  No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to