There is a new feature in trunk with needs help testing. The syntax is not 
yet finalized and may change. I allows to make some form fields conditional 
on the values of other fields. To use it you must get web2py trunk and 
clone welcome. To use in legacy apps you must still upgrade and replace 
your static/js/web2py.js with the one in welcome.

Here are 3 examples:

def index():
    """ shows bb only if aa is checked """
    db.define_table('thing', Field('aa','boolean'),Field('bb'))
    db.thing.bb.show_if = db.thing.aa==True
    form = SQLFORM(db.thing)
    return locals()

def index():
    """ shows bb only when aa is not set to "x" """
    db.define_table('thing', Field('aa','boolean'),Field('bb'))
    db.thing.aa.requires=IS_IN_SET(('x','y','z'))                           
   
    db.thing.bb.show_if = db.thing.aa!='x'                                 
    
    form = SQLFORM(db.thing)
    return locals()

def index():
    """ shows bb only when one types "x" or "y" in aa"""
    db.define_table('thing', Field('aa','boolean'),Field('bb'))
    db.thing.bb.show_if = db.thing.aa.belongs(('x','y'))                   
    
    db.thing.bb.show_if = db.thing.aa==True
    form = SQLFORM(db.thing)
    return locals()

show_if is a DAL expression wich is converted to jQuery code and embedded 
in the form. Not all expressions are supported only ==, !=, contains, and 
belongs. No logical expressions (&, |). We could add them but I personally 
believe we should keep this simple.

-- 

--- 
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/groups/opt_out.


Reply via email to