Field('dogid', label='Name',
              requires=IS_IN_DB(db(db.dog), 'dog.id', '%(name)s'))

this is a string field. It's requires to have a value in the db.dog.id set, 
but nonetheless, a string.

Field('dogid', 'integer') 

This is an integer field.

On Thursday, November 22, 2012 7:57:07 AM UTC+1, Mark Kirkwood wrote:
>
> Suppose I have an model like:
>
> db.define_table(
>     'dog',
>     Field('name'),
>     Field('type'),
>     Field('vaccinated', 'boolean', default=False),
>     Field('picture', 'upload', default=''),
>     format = '%(name)s')
>
> and a controller like:
>
> @auth.requires_login()
> def dogtest():
>
>     theId = None
>
>     form=SQLFORM.factory(
>         Field('dogid', label='Name',
>               requires=IS_IN_DB(db(db.dog), 'dog.id', '%(name)s')),
>     )
>
>     if form.process().accepted:
>         theId = form.vars.dogid
>
>         if not isinstance(theId, int):
>             response.flash = 'datatype test fail'
>             form.errors.dogid = 'wrong datatype for id'
>
>     return dict(form=form)
>
> I would expect that due to the validation rule for 'dogid' being 
> constrained to be a db.dog.id that its datatype should match (i.e int). 
> However the code above triggers the 'wrong datatype for id' error (it is in 
> fact a str).
>
> Is this expected? I was blithely thinking that it would be typed to match 
> the corresponding validation field.
>
>

-- 



Reply via email to