On Tuesday, March 8, 2016 at 3:01:48 PM UTC-5, Richard wrote:
>
> For instance how someone can acheive the same than NullBooleanField of 
> Django :
>
>
> https://docs.djangoproject.com/en/1.9/ref/models/fields/#django.db.models.NullBooleanField
>  
> <https://www.google.com/url?q=https%3A%2F%2Fdocs.djangoproject.com%2Fen%2F1.9%2Fref%2Fmodels%2Ffields%2F%23django.db.models.NullBooleanField&sa=D&sntz=1&usg=AFQjCNFC6L_ivJ7kGqBBMOORpIo7UZJIcQ>
>

In web2py, a regular boolean field allows NULLs, so I don't think we need a 
special field type. In Django, the NullBooleanField is intended to be used 
with the NullBooleanSelect widget, which actually includes three options 
(with "uknown" being equivalent to a NULL). I suppose in web2py, you could 
achieve this with a standard select widget (with a None option), and then 
use an IS_IN_SET or IS_NOT_EMPTY validator.
 

> One part of the problem with IS_NOT_EMPTY() is that it seems to be intent 
> to work only with string field type, from the book : 
>

It does work with other types of values, but there isn't much point to it 
when working with boolean form fields, as they cannot be empty by 
definition (though I suppose the distinction could be made when using the 
.validate_and_insert method).
 

> Or we can just fix IS_NOT_EMPTY() so it works with boolean type field so 
> that it returns false when the checkbox is leave blank as it should...
>

There's nothing to fix with IS_NOT_EMPTY() -- it doesn't know what type of 
field produces the value it is passed, so it cannot behave differently 
depending on the type of field. We could instead change the behavior of 
SQLFORM so it automatically converts empty checkboxes to False values, 
which would then pass validation with IS_NOT_EMPTY.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to