>
> Your correct your solution Anthony works.
>
> Massimo, I am not sure I understand what db.auth_user.username.
> requires.insert(0, MyStrangeRequirement()) is doing?
>

Massimo's solution does the same thing but by creating a custom validator 
and adding the validator to the "requires" attribute of the "username" 
field. See http://web2py.com/books/default/chapter/29/7#Custom-validators. 
A custom validator can be more convenient because once it is added to the 
field it will automatically be applied to any SQLFORM (you don't have to 
set an onvalidation function for every SQLFORM), and it will also be 
applied when records are inserted via the .validate_and_insert() method 
(onvalidation functions don't apply in that case, as it doesn't involve any 
form processing). In this case, though, we only want the validation to 
happen with login, not with other forms or inserts/updates that may include 
the username field, so a custom validator probably doesn't have any 
advantage over an onvalidation function in this case.

Anthony

Reply via email to