Thanks!

On Friday, July 13, 2012 9:54:30 AM UTC-5, Niphlod wrote:
>
> uhm, I tested your on trunk, and also switched some things because I don't 
> have db.raw_material and db.run_as_rm, but
>
> def add_composition():
>     form = SQLFORM.factory(
>         Field('dog_id', requires = IS_EMPTY_OR(IS_IN_SET(['a','b','c']))),
>         Field('cat_id', requires = IS_EMPTY_OR(IS_IN_SET(['a','b','c']))),
>         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)
>
> works for me (i.e. error is shown if dog_id AND cat_id are selected, and 
> if there is no selection at all).
> PS: works the IS_IN_DB version AND the IS_IN_SET version
>
> On Friday, July 13, 2012 4:31:09 PM UTC+2, joe wrote:
>>
>> 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
>>
>

Reply via email to