yes and no.

a validator is uniquely associated to a field and validates that one
field but it can validate depending on the values of other variables
(request.vars)

example:

form=FORM('password:',INPUT(_name='password1',requires=IS_NOT_EMPTY
()),
                   'password again:',INPUT
(_name='password2',requires=IS_EXPR('value==%s' % repr
(request.vars.password1))),
                   INPUT(_type='submit'))

You can also create custom validators that share a data structure (for
example a dictionary) so that they can exchange information. They will
be evaluated in the order the fields are displayed.

Massimo


On Jan 7, 9:43 am, Manakel <manakel...@gmail.com> wrote:
> Wow, very fast answers :-)
>
> Can a custom validator get access to several fields of the Form?
>
> For example, if i make a checkClosingDate validator ,
> how can my validator read both the ClosingDate (the date to validate)
> and the "Fixing Date" (support data)
> - in the creation case where Fixing date is another field of the
> SQLForm
> - in the update case where Fixing date is an attribute of the record
> being updated
>
> Regards
>
> On Jan 7, 2:48 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > you need to define your own validators like
>
> > class VALIDATOR:
> >     def __init__(self,...): pass
> >     def __call__(self,value):
> >          if valid value: return (value,None)
> >         else: return (value, error_message)
>
> > On Jan 7, 2:22 am, Manakel <manakel...@gmail.com> wrote:
>
> > > Hello All,
>
> > > I'm just discovering web2py and i'm not able to wrap my mind about the
> > > Form level validation inside it.
>
> > > Let's say we talk about a defect. This defect has a "Fixing
> > > Date" (date where provider deliver the fixing code in integration
> > > system) and a "Closing Date" (date where the customer confirm issue is
> > > solved in production system)
>
> > > Basically, i understand how i can check the data integrity when using
> > > SQLForm.
> > > -> this will check that the "Closing date" is a real date
> > > But i don't understand how i can perform business level check when
> > > using SQLForm
> > > -> this may be real date , but it's a date in the future so i don't
> > > allow the insertion/ update of the record (Business rules)
> > > -> this may be a real date, and date is today or in the past, but it's
> > > before the "Fixing Date" so i don't allow the insertion/ update of the
> > > record (Business Rules)
>
> > > What is the recommended way to handle this kind of form level
> > > validation in web2py?
> > > (hopefully without having to save non valid data (versus business
> > > rules) inside the db during the process)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to