Thursday, 31 January 2019

web2py: detect change in dropdown widget

How can we detect a change from a dropdown widget so that code can be executed?

Table loan references table services. Both have field called interest_rate. When I change loan.service via dropdown I'd like to reflect the corresponding interest_rate from services table to loan table.

How can this be achieved?

model

db.define_table('services',
                Field('service_name',requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'services.service_name')]),
                Field('service_type','reference service_types',requires=IS_IN_DB(db,db.service_types.id,
                                                                                '%(type_name)s',
                                                                                error_message='not in table',
                                                                                zero=None),
                                                                                ondelete='RESTRICT',
                                                                                ),
                Field('interest_rate','decimal(15,2)',requires=IS_DECIMAL_IN_RANGE(0,100)),
                Field('max_term','integer'),
                auth.signature,
                format='%(service_name)s',
    )

db.define_table('loan',
    Field('service','reference services',requires=IS_IN_DB(db,db.services.id,
                                            '%(service_name)s',
                                            error_message='not in table',
                                            zero=None),
                                            ondelete='RESTRICT',),
    Field('member_id','reference members',requires=IS_IN_DB(db,db.members.id,
                                            '%(member_name)s',
                                            error_message='not in table',
                                            zero=None),
                                            ondelete='RESTRICT',
                                            label='Member'),
    Field('amount','decimal(15,2)',requires=IS_DECIMAL_IN_RANGE(1000)),
    Field('interest_rate','decimal(6,2)',default=10),
    )   



from web2py: detect change in dropdown widget

No comments:

Post a Comment