[web2py] Re: Field validation interaction

2010-04-02 Thread Yarko Tymciurak
On Apr 2, 10:32 am, Jonathan Lundell wrote: > I think I've seen an answer to this one, but I can't find it. > > I've got a form with two Field's, both IS_IPV4(). The validation I'm after is > that one or both must be present; the only invalid case is both of them null. > sort of a situation

[web2py] Re: Field validation interaction

2010-04-02 Thread mdipierro
db.table.field1.requires=IS_NULL_OR(IS_IPV4()) db.table.field2.requires=IS_NULL_OR(IS_IPV4()) if request.vars.field1 else IS_IPV4() On Apr 2, 10:32 am, Jonathan Lundell wrote: > I think I've seen an answer to this one, but I can't find it. > > I've got a form with two Field's, both IS_IPV4(). The

[web2py] Re: Field validation interaction

2010-04-02 Thread Yarko Tymciurak
On Apr 2, 7:14 pm, mdipierro wrote: > db.table.field1.requires=IS_NULL_OR(IS_IPV4()) > db.table.field2.requires=IS_NULL_OR(IS_IPV4()) if request.vars.field1 > else IS_IPV4() Thank you for this, Massimo - this is a nice, compact idiom for using existing validators; I hadn't considered (don't know

[web2py] Re: Field validation interaction

2010-04-02 Thread mdipierro
Yes. No one solution is obviously better. It is good to have some options. Massimo On Apr 2, 8:45 pm, Yarko Tymciurak wrote: > On Apr 2, 7:14 pm, mdipierro wrote: > > > db.table.field1.requires=IS_NULL_OR(IS_IPV4()) > > db.table.field2.requires=IS_NULL_OR(IS_IPV4()) if request.vars.field1 > > e

[web2py] Re: Field validation interaction

2010-04-02 Thread mdipierro
You can also do db.table.field1.requires=IS_NULL_OR(IS_IPV4()) db.table.field2.requires=IS_NULL_OR(IS_IPV4()) def at_least_one(form): if not form.vars.field1 and not form.vars.field2: form.errors.field2='cannot be empty if field1 is empty' form.errors.field1='cannot be empty

[web2py] Re: Field validation interaction

2010-04-02 Thread Yarko Tymciurak
On Apr 2, 11:06 pm, mdipierro wrote: > You can also do > > db.table.field1.requires=IS_NULL_OR(IS_IPV4()) > db.table.field2.requires=IS_NULL_OR(IS_IPV4()) > > def at_least_one(form): >     if not form.vars.field1 and not form.vars.field2: >          form.errors.field2='cannot be empty if field1 is

Re: [web2py] Re: Field validation interaction

2010-04-02 Thread Jonathan Lundell
On Apr 2, 2010, at 5:14 PM, mdipierro wrote: > db.table.field1.requires=IS_NULL_OR(IS_IPV4()) > db.table.field2.requires=IS_NULL_OR(IS_IPV4()) if request.vars.field1 > else IS_IPV4() Ah, that's the one I remember. Now I have to decide between this approach and Yarko's. Nice to have two >

Re: [web2py] Re: Field validation interaction

2010-04-02 Thread Jonathan Lundell
On Apr 2, 2010, at 8:05 PM, mdipierro wrote: > Yes. No one solution is obviously better. It is good to have some > options. Yarko's approach allows for a more general error message, at the expense of not associating it with a particular input field. In my case, I think I see a way of phrasing t