Just a note, this seems to fail in other situations as well
My code:
def add_composition():
form = SQLFORM.factory(
Field('dog_id', requires = IS_EMPTY_OR(IS_IN_DB(db,
db.raw_material))),
Field('cat_id', requires = IS_EMPTY_OR(IS_IN_DB(db, db.run_as_rm))),
Field('number', 'double', requires = IS_NOT_EMPTY()),
Field('comment', 'text'),
Field('date', 'date'),
onvalidation = validate_survey)
if form.process(onvalidation = validate_survey).accepted:
response.flash = 'success'
redirect(URL('index'))
return dict(form=form)
def validate_survey(form):
if form.vars.dog_id != None and form.vars.cat_id != None: #someone
can't have a dog and a cat
form.errors.dog_id = "Only one of these"
form.errors.cat_id = "Only one of these"
elif form.vars.dog_id==None and form.vars.cat_id==None: #but they need
a pet (this is a simplified example)
form.errors.dog_id = "You need a material"
form.errors.cat_id = "you need a material"
The validation somehow works if they are both empty, but not if they are
both populated. (I have tested 'if form.vars.dog_id and form.vars.cat_id:'
and that fails as well