On Monday, September 2, 2013 6:43:56 AM UTC-7, Mirko wrote:

> Ok, but if the default validator for a list:reference field does allow 
> zero options to be selected, required=True and required=False makes no 
> difference, isn't it ?
>

If you do an insert via a form, I think it will pass in [] or [''], which 
doesn't trigger an error with required=True (because as you observed, the 
empty list gets converted to the string value '||', which is not an empty 
string). However, if you do a manual insert and simply exclude a value for 
the list:reference field, required=True will result in an error in that 
case. So, there is a difference between required=True and required=False.

Now that I think about it, this is probably the right behavior. When you 
specify the IS_IN_DB validator (with multiple=True) and submit via a form, 
zero selections are allowed (and encoded as an empty list), and in that 
case, required=True does not conflict with the validator. However, if you 
do a manual insert, required=True does require a value (even if that value 
is an empty list). The idea is that an empty list is a valid value for a 
list:-type field, so required=True triggers an error only if there is no 
value inserted at all.

Anthony

-- 

--- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to