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

Roger Ineichen dev at projekt01.ch
Fri Aug 29 08:07:22 EDT 2008


Hi Hermann

> Betreff: Re: [Zope-dev] z3c.form - extraction from sequence widget

[...]

> > I think you *could* interpret it so that a boolean field that's 
> > required really means "you have to tick this box" (e.g. an 
> "I agree to 
> > these terms and conditions" type scenario).
> 
> My idea is to look at it bottom-up: Think about schemas 
> without widgets at all, e.g. in a totally different 
> non-zope/form scenario. To my mind, it's obvious, that 
> required="True" means, that some sort of value has to be 
> given and not, that the value has to be of a specific type 
> (e.g. "True" for Boolean).
> 
> > To put it the other way - how would you have a non-required boolean 
> > field represented by a checkbox? You really need three states then: 
> > True False and None, which you can't get with a checkbox.
> 
> Well, and then there's the representation of fields by 
> widgets. And, right, it's impossible to provide no value via 
> a checkbox or a radio-box offering "yes/no". And, yes, this 
> somehow obsoletes the "required" 
> constraint. But isn't this perfectly normal for widgets? For 
> instance, a Choice, which is represented by a drop-down 
> widget, will also never return None.
> 
> 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. That means the first
time if no value is given the Bool field could return None
as default=None. Which indicates that if missing_value=None
is used the input is missing. But.... it is not valid to
do that! Why? In some use case:

zope.schema.Bool(
    required=True,
    default=None,
    missing_value=None)

will raise exceptions. But why? If this field get used
for a global configuration and will apply the defualt
value if nothing get defined and the valdation get invoked,
then this is will raise a validation error during zope 
start up and zope will not start.

I think it's always bad idea to use default=None for Bool
fields. Because of it's invalid defaults.

Some background;
Let me explain how the schema and the different field 
attribute combination work.

If a field defines:
required=True
That means you must provide input if you store a value.

But what means input for the field? 
This is defined in:
missing_value='foo'
That means everything except 'foo' is input.
But doesn't mean that everything is valid input.

the missing_value marker is a very important concept.
It defines if input is given. This makes it possible
to use None or False as input (doens't matter if valid or not)

The widget and also the field has validation methods for find
out if a value is valid or not which get in use if you store 
something.

In general I think if an attribute should provide states 
like 

- selected
- not selected
- no yet set

and at least a given state could set back to *not yet set* 
after the state was set. A boolean with a Bool field is 
defently the wrong type for such an attribute. If you like
to do so, you need to define a choice which you can 
choose form and use another HTML input component then 
a single checkbox input or two radio (yes, no) elements.

Hermann,
can you you give me a short description of the problem what
this thread describes and what is missing in z3c.form?
If there is a real problem in the behavior or a missing widget
I like to fix that. But right now I don't really understand 
the real problem. Sorry but I didn't follow the full mail thread.


Regards
Roger Ineichen


> Best Regards,
> Hermann
> 
> --
> hermann at qwer.tk
> GPG key ID: 299893C7 (on keyservers)
> FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7 
> _______________________________________________
> 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