On Wednesday, June 24, 2015 at 2:34:40 PM UTC-7, goome wrote:
>
> > Or changing the validator to provide the NULL.
>
> how could it be done? in the model?
>

I believe so, but I've only played around a little with validators.  The 
other suggestions may be simpler for you.
Or you can search for custom validators among the old posts, and check the 
web2py book
<URL:http://www.web2py.com/books/default/chapter/29/07/forms-and-validators#Custom-validators>

In my db.py, I have (at the end) this terribly unsophisticated custom 
validator.


from gluon.validators import Validator

class IS_HEXSTR(Validator):
    def __init__(self, format='%c%c%c%c', error_message='must be a 4-digit 
hex string like A09F!'):
        self.format = format
        self.error_message = error_message
    def __call__(self, value):
        try:
            if len(value) != 4:
                raise ValueError
            intvalue = int(value, 16)
            print "should be valid " + str(intvalue)
            return (value, None)
        except ValueError:
            print "invalid " + value
            return (value, self.error_message)
        except Exception as e:
            print "invalid " + value
            raise e
    def formatter(self, value):
        return value.upper()



-- 
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 the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to