thank you so much for your hints anthony, the error didn't appears anymore,
but the validation is not run
def __date_comparation(form):
if request.function == 'booking_add':
if form.vars.from_date > form.vars.to_date:
form.errors.to_date = 'To Date must greater than From Date'
i know there is a mistaken on my validation code, could you give me a
pointer how to fixed it?
thank you very much
On Fri, Apr 22, 2011 at 6:07 PM, Anthony <[email protected]> wrote:
> The 'requires' attribute of a field has to be a validator or list of
> validators (validators are callable objects), not just any boolean test. I
> think you'll need a custom validator:
> http://web2py.com/book/default/chapter/07#Custom-Validators. You might
> also consider using an 'onvalidation' function with your form:
> http://web2py.com/book/default/chapter/07#onvalidation.
>
> Anthony
>
> On Friday, April 22, 2011 3:35:22 AM UTC-4, 黄祥 wrote:
>
>> hi,
>>
>> is it possible to compare db field datetime during form validation?
>> e.g.
>> db.define_table('duration',
>> Field('from',
>> 'datetime',
>> requires = IS_DATE()
>> ),
>> Field('to',
>> 'datetime',
>> requires = [IS_DATE(),
>> request.vars.from < request.vars.to]
>> )
>> )
>>
>> an error occured said:
>> TypeError: 'bool' object is not callable
>>
>> also i tried:
>>
>> db.define_table('duration',
>> Field('from',
>> 'datetime',
>> requires = IS_DATE()
>> ),
>> Field('to',
>> 'datetime',
>> requires = [IS_DATE(),
>> form.vars.from < form.vars.to]
>> )
>> )
>>
>> an error occured said :
>> NameError: name 'form' is not defined
>>
>> does anyone have a clue to solve it?
>>
>> thank you very much for your kind attention
>
>