Making validators trigger only when data is present

24 views
Skip to first unread message

REM

unread,
Sep 17, 2013, 2:44:14 PM9/17/13
to web...@googlegroups.com
I have a form field which is not required, but when it is submitted with data, I want the data to be validated. The problem is, I get the validator triggering when the form is submitted with no value in that field. I want it to wait until there's data in there to validate it and ignore it if blank. I thought I could get this behavior with required=False and then using requires= validators, but it is failing the validation every time when there's no data in the field. How do you get it to validate data that's present and ignore blanks?

The field in question is in the db.py as follows:

    Field('special_code1', 'string', length=200, required=False, label='Special Code 1',
           requires
=[IS_LENGTH(maxsize=200),
                     IS_MATCH
('^[a-zA-Z0-9\s\#\.\$\-\_]+$', error_message='Character Not Allowed.')]
         
),



There are no other controllers acting on this data, and no combination of anything I try above gets me what I want.





Anthony

unread,
Sep 17, 2013, 2:56:16 PM9/17/13
to web...@googlegroups.com
requires=IS_EMPTY_OR([IS_LENGTH(maxsize=200),

                     IS_MATCH
('^[a-zA-Z0-9\s\#\.\$\-\_]+$', error_message='Character Not Allowed.')])


Anthony

REM

unread,
Sep 17, 2013, 3:00:44 PM9/17/13
to web...@googlegroups.com
Many EXTREME thanks for your kind help!!!!

REM

unread,
Sep 17, 2013, 4:02:53 PM9/17/13
to web...@googlegroups.com
Actually, in checking out this solution, there is no change. It still always triggers the validator.

What could be causing this?




On Tuesday, September 17, 2013 2:56:16 PM UTC-4, Anthony wrote:

REM

unread,
Sep 17, 2013, 4:12:30 PM9/17/13
to web...@googlegroups.com
In  further exploration, there's some inconsistencies in behavior. Sometimes it triggers the error and sometimes it doesn't. I haven't yet figured out what the determining factor is.

Robert Moore

unread,
Sep 17, 2013, 5:06:59 PM9/17/13
to web...@googlegroups.com
Well, by now I have tested the heck out of this thing, and the ill behavior has gone away and I can't get it to come back.....

My natural curiosity wants to know why but, in any case, good riddance!






--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/HiTi-ofCemA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages