Re: formEncode - complicate validate form

Ian Bicking <[email protected]>
Newsgroups gmane.comp.python.formencode
Message-ID <[email protected]>
Grzesiek Slusarek wrote:
> Hi all. I'm using formEncode to validate my forms, and I'm 
> stopped
> on how to do a complicated validation that depened on what forms
> element was filled. I mean I want to validate file that is 
> uploaded but only when the checkbox on the form is checked. How 
> to do this?
> In python code this looks like:
> 
> if form.radio is checked:
>     #validate file form that i uploaded
>     code...
> else:
>     #validate other forms fields
>     if form.login != '' and form.password !='':
> 	code..
>     else:
> 	code..

You want a FormValidator, because you are validating pieces together. 
An example of this is 
formencode.validators.RequireIfMissing/RequireIfPresent.  You might want 
to look at the implementation; how you use that field is:

class MySchema(Schema):
     other fields...
     chained_validators = [RequireIfPresent(required='birthday', 
present='i_am_over_18')]

Form validators validate the entire dictionary that is submitted.


-- 
Ian Bicking  /  [email protected]  /  http://blog.ianbicking.org


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.