I do not see any error in the code I propose you print the output of last_names = get_last_names( ) to make sure the second time the function is called (when validation is done), the output is the same as the first time (when the dropbox is generated).
On Mar 2, 12:46 pm, "[email protected]" <[email protected]> wrote: > I have a form with a string field that uses the IS_IN_SET validator. > The set of strings that is allowed must be generated dynamically each > time the form is generated. So I add the validator in the controller. > ( See the snippet below. ) > > The problem is that sometimes I get "value not allowed" validation > errors from that field. Why? I am restricted to selecting only the > items in the list given to IS_IN_SE. It seems like it would be > impossible to select a value that is not allowed. > > Maybe adding the validator in the controller is not correct but I > don't know what is the correct way! > > Here is a snippet showing the controller and also the table definition > from the db.py file. (I stripped out the code for other fields just to > make the snippet shorter. ) > > Thanks in advance! > > ======================= > controller > ======================= > > def register_user_custom_form(): > > # Dynamically get the list of valid last names > last_names = get_last_names( ) # Call some function to get the > list > # Set the validator based on that > db.reg_test.last_name.requires = IS_IN_SET( last_names, zero = > "Select a Last Name" ) > > form=SQLFORM(db.reg_test) > if form.accepts(request.vars,session): > response.flash='Your account has been created' > elif form.errors: > response.flash='Your account has not been created' > > ### and get a list of all users > records=SQLTABLE(db().select(db.reg_test.ALL)) > return dict(form=form,records=records) > > ================= > table definition > ================= > > db.define_table('reg_test', > Field('first_name',required=True,notnull=True,writable=True, > label="First Name"), > Field('last_name',required=True,notnull=True,writable=True, label= > "Last Name"), > ) > db.reg_test.first_name.requires = IS_NOT_EMPTY() -- You received this message because you are subscribed to the Google Groups "web2py-users" 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.

