All, I am trying to get a solution to the above problem, I am using a onvalidation function. If have_coupon is checked then I call IS_NOT_EMPTY and set the form.errors.coupon_code manually. This is not ideal but it works.
However I cannot seem to get a work around for a dropdown input i.e. IS_IN_SET as this is needed on the model to create the correct input but inturn fails the processing of the form as onvalidation doesnot get called. Any help would be great. Regards, James On Wednesday, December 2, 2020 at 12:35:15 PM UTC+10 James O' Driscoll wrote: > Hello all, > > I have a question regarding conditional fields and using validators. > > Take the example from the book with a slight change: > > db.define_table('purchase', Field('have_coupon', 'boolean'), > Field('coupon_code', requires=IS_NOT_EMPTY())) > > with controller: > > def index(): > db.purchase.coupon_code.show_if = (db.purchase.have_coupon==True) > form = SQLFORM(db.purchase).process() > return dict(form = form) > > show_if works well but if i need validators in place for when say > have_coupon is true, to validate coupon_code I get an error when > have_coupon is false as coupon_code is empty. > > I would prefer to keep the validator on the model, is there a way to > accomplish this. > > Regards, > James > > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/a9cc6d8f-41ee-483b-8718-e3c286ae35a4n%40googlegroups.com.