You can create your own field-level validators
class validator:
def __init__(self,error_message): self.error_message=error_message
def __call__(self,value):
if success: return (value,None)
else: return (value,self.error_message)
both form.accept and crud.create/crud.update take a parameter
onvalidation
onvalidation can point to a function that takes a form, reads
form.vars and writes form.errors
def f(form):
if not form.vars.a==form.vars.b: form.errors.b="should be == a"
form = crud.create(...., onvalidation = f)
On Jan 11, 6:13 am, "KONTRA, Gergely" <[email protected]> wrote:
> Hi!
> I have a status "enumeration" for a status in one of my tables. I'd
> like to store it, as an integer, and access it with constants. Where
> should I define these constants (I guess I should in db.py), and how
> can I access them in the controller?
>
> And some random things about validators:
> date validation: I miss a date validator, which allows dates
> before/after a specific date or at least current time.
>
> validators: despite of the names is_*, they do not do just checking,
> they perform type conversions, change appearance of a form widget ...
> (Currently I have no idea of better names)
>
> Multi-field validation is not currently possible AFAIK. (As I can see,
> you can skip dbio, and validate manually). However, for transparent
> model validation, it would be necessary. So, your data is validated
> upon a plain insert.
> Isn't it possible to have some optional validation hook, in term of a
> function, which gets all the form data, and can judge about the
> validation of the form? This validator should be able to signal errors
> like: field a should be greater than field b, or: if a is empty, b
> could be anything (it is ignored).
>
> thanks
> Gergo
>
> +-[ Gergely Kontra <[email protected]> ]------------------+
> | |
> | Mobile:(+36 20)356 9656 |
> | |
> +- "Olyan lángész vagyok, hogy poroltóval kellene járnom!" -+
--
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.