On Friday, January 20, 2017 at 11:22:14 AM UTC-5, Andrea Fae' wrote:
>
> Hello guys, I need to have a dependent field in a table.
> If the field "is_active" = True then I cannot insert in the field "date"
> nothing.
> If the field "is_atvie" = False then I can or not insert something in the
> field "date".
> How to do in the definition of table? Or it's better to use "onvalidation"
> function?
>
You can handle validation involving multiple fields via onvalidation. You
can also conditionally specify whether the field is writable based on
request.post_vars.
Field('mydate', 'date', requires=IS_EMPTY_OR(IS_DATE()),
writable=request.post_vars.is_active == True)
In the UI, you can also conditionally hide the date field (though you
should still handle the validation/writable status on the server) -- see
http://web2py.com/books/default/chapter/29/07/forms-and-validators#Conditional-fields.
Anthony
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.