3

In web2py, say I have modified the default auth_user table by adding a field called 'agent_code'. This field should include values from another table:

auth_table = db.define_table(
    auth.settings.table_user_name,
    Field('first_name', length=128, default=''),
        ...more fields here...,
    Field('auth_age_cod', length=512,default=None))

auth_table.auth_age_cod.requires = \
    IS_IN_DB(db, db.agea.agea_cod,
             '%(agea_cod)s - %(agea_name)s',
             error_message='Agent not in DB')

I want users to be able to identify themselves as agents during registration.

The user registration form now shows the dropbox to allow for agent selection, but includes a blank option at the start. For some reasons this is not acceptable in our system.

After investigating the source code for the validator, I found that the IS_IN_DB validator has a parameter called 'zero'. This is by default set to '' (empty string) and creates a blank option in the droplist.

So, to remove the blank option, change the validator to:

IS_IN_DB(db, db.agea.agea_cod,
         '%(agea_cod)s - %(agea_name)s',
         error_message='Agent not in DB',
         zero=None)
nerfologist
  • 761
  • 10
  • 23
  • 2
    It looks like your asking and answering your own question which is fine but you should submit your solution as an answer and then accept it. – User Oct 22 '13 at 05:32

1 Answers1

4

Your question is unclear, but if you are asking if the zero argument in IS_IN_DB is for that purposes, it is. The web2py manual says that the argument zero in IS_IN_DB works like zero in IS_IN_SET

And for IS_IN_SET the manual states: The zero argument is optional and it determines the text of the option selected by default, an option which is not accepted by the IS_IN_SET validator itself. If you do not want a "choose one" option, set zero=None

Ana
  • 163
  • 5