Widgets
web2py provides a flexible method for applying various input and output controls to your form fields. Input controls are called widgets and output controls are called representations. Here is a sample widget taken directly from the book (7.5):
def my_string_widget(field, value):
return INPUT(_name=field.name,
_id="s_s\" field._tablename, field.name),
_class=field.type,
_value=value,
requires=field.requires)
Field('comment', 'string', widget=my_string_widget)
This makes it very easy to customize your forms in a DRY manner. The application below includes 8 ready to use widgets. Here are screenshots of a few:




Download application and enjoy! All of the widget code (excluding any required javascript, css or images) is in A_widgets.py in the models folder.


Comments (4)
0
tom 2 years ago
def user(): return dict(form=auth())in views\default\user.html{{if request.args(0)=='login':}} {{=form.custom.begin}} {{#table with login custom fields}} . . . {{=form.custom.submit}} {{=form.custom.end}} {{elif request.args(0)=='register':}} {{=form.custom.begin}} {{#table with registration custom fields (for example):}} {{=form.custom.label01}}{{=form.custom.widget01}} {{=form.custom.label02}}{{=form.custom.widget02}} {{=form.custom.label03}}{{=form.custom.widget03}} . . . {{=form.custom.submit}} {{=form.custom.end}}In the registration part I'd like to include your cascading_select widget. In my database I have 3 separate tables with state, city and zipcode. During registration I'd like to add id's of this 3 data (selected state, city, and zipcode) to user record. If I understand it correctly in my user_auth table I should have fields like state, city and zipcode. Can you tell me how should I modify my def user(): and registration form to have it working? Or maybe I need to modify something else yet? I'll appreciate your help. Best regards.0
tom 2 years ago
0
mrfreeze 2 years ago
0
asmancom 2 years ago