Conditional validation

38 views
Skip to first unread message

Andrea Fae'

unread,
Jan 20, 2017, 11:22:14 AM1/20/17
to web2py-users
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?
Thanks

Andrea Fae'

unread,
Jan 21, 2017, 12:06:44 PM1/21/17
to web2py-users
Where can I find conditional validation documentation?

Anthony

unread,
Jan 21, 2017, 5:57:44 PM1/21/17
to web2py-users

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
Reply all
Reply to author
Forward
0 new messages