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

Roger Ineichen dev at projekt01.ch
Sat Aug 30 17:07:02 EDT 2008


Hi Martin

> Betreff: Re: [Zope-dev] z3c.form - extraction from sequence widget
> 
> Hi Roger,
> 
> >> Btw., it is possible to have a three-state widget for 
> booleans, such 
> >> as a drop-down widget, that includes "True/False/None", 
> although it 
> >> may not make much sense.
> > 
> > No that's not possible! Because you can't save anything 
> then False or 
> > True in a Bool field.

I was a little bit unclear. I meant that the widget can't 
save back None as a new value after True/False was set.

> Really? How is this different to having a not-required Int, 
> Float, TextLine or whatever field, with no default? Do they 
> then semantically default to 0, 0.0, "" etc, or are they 
> expected to be None? My assumption is that they're None when 
> not explicitly set.

Yes, you are right the default is set to None
like any other field which doesn't define something else.

The problem is, if you use a widget and the widget 
uses None as an option e.g. True/False/None for 
act as (True, False and not set) then the field
validation whould not allow to set anything then
True or False as a value.

The initial value could be None, but after set to
True or False this initial (None) state can't get 
set again. That's sometimes useful but sometime not.

> > I think it's always bad idea to use default=None for Bool fields. 
> > Because of it's invalid defaults.
> 
> I guess that depends on whether you think "not set" means 
> "invalid". In SQL, for example, any field type can accept 
> NULL (unless the column is defined NOT NULL).

I see your point, None is often use as an indicator
for a not set value. I'm not so sure if this is a good
concept for any use case. I use that concept too im my 
projects for Bool fields. But I also use some Choice
fields with explicit (True/False/None) values for allow
to reset a already set value.

What I tried to say is: None is a possible inital value
but this value is invalid for Bool fields. If the goal
is to indicate a *not set value* then we are fine. If you
set the field to require=True and that's fundamental part
of your business logic, then it could end in a nightmare
because of the invalid default. At least if the application
will access the field value before someone changed that
to a valid value.


Regards
Roger Ineichen

> Martin
> --
> Author of `Professional Plone Development`, a book for 
> developers who want to work with Plone. See 
> http://martinaspeli.net/plone-book
> 
> _______________________________________________
> Zope-Dev maillist  -  Zope-Dev at zope.org
> http://mail.zope.org/mailman/listinfo/zope-dev
> **  No cross posts or HTML encoding!  ** (Related lists -  
> http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope )
> 



More information about the Zope-Dev mailing list