There are two separated things here. One is presentation of required 
attributes only, the other is validation of the from.
The first one could be solved with the "conditional field" approach 
described in the book. If you are not sure what are
the ids for generated form elements, simply view the generated HTML code in 
your browser.

To implement the validation you need to use your own function in the 
controller:
def validate_survey(form):
    if "M" == form.vars.sex:
        if not form.vars.fav_car:
            form.errors.fav_car = "favorite car is required"
        if not form.vars.fav_sport:
            form.errors.fav_sport = "favorite sport is required"
    elif "F" == form.vars.sex:
        if not form.vars.fav_soapie:
            form.errors.fav_soapie = "favorite soap opera is required"
        if not form.vars.fav_perfume:
            form.errors.fav_perfume = "favorite perfume is required"

And the use it with the grid:
grid = SQLFORM.grid(db.survey, onvalidation=validate_survey)

Reply via email to