pardon me, the problem is solved after a few modification in function. thank
you so much for your kind help massimo. it seems that the validation on form
is run after the validation that define on the models (db.define_table).

On Sat, Apr 23, 2011 at 9:41 AM, Massimo Di Pierro <
massimo.dipie...@gmail.com> wrote:

> I am on the road. I will take a look asap but may have to wait Sunday.
>
> On Apr 22, 2011, at 6:41 PM, Stifan Kristi (Kou Shou) wrote:
>
>  thank<pixel.png> you so much for pointers pbreit and massimo, it's
> correct that before i changed my from database field into from_date because
> i think it's a keyword. i've already tried to modified my code, but the date
> validation is not run using crud, here's my code :
>
> db.define_table('booking',
>                 Field('from_date', 'date', requires = IS_DATE()),
>                 Field('to_date', 'date', requires = IS_DATE()))
>
> def __add_2(table):
>     form = crud.create(table, onvalidation = __date_comparation, next =
> URL(request.application, request.controller, 'index'))
>     return dict(form = form)
>
> 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 start before From Date'
>
> def booking_add():
>     return __add_2(db.booking)
>
> any hints or pointers for this problem is highly appreciate.
>
> thank you very much in advance
>
> On 04/23/2011 12:56 AM, Massimo Di Pierro wrote:
>
> mind that "end" is a keyword in sql and you can have problems with a
> field called "end".
>
> On Apr 22, 12:34 pm, pbreit <pbreitenb...@gmail.com> <pbreitenb...@gmail.com> 
> wrote:
>
>  I think you were on the right track. I think naming the field "from" might
> have been a problem. I assume with your last function you had renamed the
> fields from_date and to_date? The if request.function might not be
> necessary. Remember that any functions with parameters cannot be accessed
> from the browser.
>
> This works OK:
>
> db.define_table('duration',
>     Field('start', 'datetime'),
>     Field('end', 'datetime'))
>
> def process_duration_form(form):
>     if form.vars.start > form.vars.end:
>         form.errors.start = 'start must be before end'
>
> def duration():
>     form = SQLFORM(db.duration)
>     if form.accepts(request.vars, session,
> onvalidation=process_duration_form):
>         response.flash = 'form accepted'
>     elif form.errors:
>         response.flash = 'form has errors'
>     else:
>         response.flash = 'please fill out the form'
>     return dict(form=form)
>
>   <steve_van_christie.vcf>
>
>
>

Reply via email to