On Jan 2, 11:26 pm, mdipierro <[email protected]> wrote:
> This is a good point but the fact is that
>
>     db.table.field.requires=[IS_IN_SET(['a','b','c'])]
>
> is different from
>
>     db.table.field.requires=IS_IN_SET(['a','b','c'])
>
> Both validate the input in the same way but the latter also make a
> select/option dropbox.

That's true, but in that case, couldn't web2py handle it by looping
through and generating the options for a dropbox?

you could say that allowing lists might lead to the situation where
there is more than one validator that provide 'options' attribute',
but that's the user's fault. perhaps web2py could warn in such an
instance.

> Moreover doing
>
>     db.table.field.requires.append(....)
>
> assumes that you can append any validator you want and you do not care
> about previous validators. This is not the case since validators are
> also filters. For example IS_INT_IN_RANGE() converts the input string
> to an integer, thus it cannot be piped with validators that expect a
> string.

that's true, however logic in the form validation should handle such
cases, because in web2py currently there's nothing stopping you from
combining incompatible validators. so, in the situation you raised,
currently one could do this:

db.table.field.requires = [IS_INT_IN_RANGE(), IS_LOWER()]

but whether it works is a different story, the user shouldn't have
done placed two incompatible validators.

so requires.append-ing an incompatible validator is not a problem, or
rather, it isn't a new problem, and it is not a problem that cannot be
prevented by the user.

> Massimo
>
> On Jan 2, 9:12 am, rctay <[email protected]> wrote:
>
> > Hi,
>
> > (this is somewhat related to my 
> > posthttp://groups.google.com/group/web2py/browse_thread/thread/fa10eaed05...)
>
> > i noticed that there is a somewhat inconsistent usage of the
> > 'requires' attribute as a list sometimes and a scalar at others.
>
> > for example, in the SQLFORM __init__ treats the field 'requires' as a
> > scalar, while the validation method in INPUT makes sure it is a list.
>
> > i hope that the 'requires' field is a list by default (at construction
> > time).
>
> > this would not only help in type safety, it would also be convenient
> > for the user, who can just do
>
> >   field.requires.append(IS_NOT_EMPTY())
>
> > and he wouldn't overwrite the automatically-generated validator
> > (although he could do something like
>
> >   field.requires = [IS_NOT_EMPTY(), field.requires]
> > )
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to