def tst() def validate_form(form): err = form.errors if form.vars.SearchType == "typeMonthly": form.errors = { k:v for k,v in err.items() if k in [ "monthlyMonth",] } elif form.vars.SearchType == "typeWeekly": form.errors = { k:v for k,v in err.items() if k in ["weeklyWeek" ,] } elif form.vars.SearchType == "typeDaily": form.errors = { k:v for k,v in err.items() if k in ["dailyDay",] } else: pass if not form.errors: form.accepted = True
not_empty = "This field cannot be empty!" form = FORM(INPUT(_name="monthlyMonth", requires=IS_NOT_EMPTY( error_message=not_empty)), INPUT(_name='weeklyWeek', requires=IS_NOT_EMPTY( error_message=not_empty)), INPUT(_name='dailyDay', requires=IS_NOT_EMPTY(error_message= not_empty)), INPUT(_name='SearchType', requires=IS_NOT_EMPTY( error_message=not_empty)), ).process(formname="getReportForm",onvalidation= validate_form, onsuccess="",onfailure="") return dict(form=form) Hi, Above code represents the controller with my custom form in it. On the html side I have a few lines of jQuery, which disable fields accordingly. Now my problem is, that I can't properly validate form, because all fields are validated all the time. I thought I'll incorporate the onvalidation callback and process form.error leaving only errors, which make sense, but then I've spotted this nonsense in the docs: http://web2py.com/books/default/chapter/29/07/forms-and-validators#onvalidation The onvalidation argument can be None or can be a function that takes the > form and returns nothing. > Such a function would be called and passed the form, immediately after > validation (*if validation passes*) and before anything else happens. Note: if validation passes. So my logic became a waste of time, as code is never executed, as form always fails... Does anyone have a better strategy?? Thanks -- 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.