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 (5)
0
asmancom 14 years ago
0
tom 14 years ago
0
mrfreeze 14 years ago
0
tom 14 years ago
0
beefheart 11 years ago
To get this working on newer versions of web2py add this to your model: