= A more complex example =
Here is a rather more complex example that uses a number of different input types.
Here's the model.
{{{#!python
class User:
def __init__(self):
self.name = ''
self.an_int = 0
self.a_float = 0.0
self.country = 0
self.password = ''
self.active = False
}}}
The form that describes how we want it laid out
{{{#!python
# Slightly abridged list of all the countries in the world.
country_names = (
'Australia', 'Belgium', 'Cuba',
'Greenland', 'Madagascar', 'Netherlands',
'Switzerland', 'Uzbekistan', 'Zimbabwe'
)
country_menu = [e for e in enumerate(country_names)]
fields = (
TextField('Name', 'name', required=True),
IntegerField('Integer', 'an_int'),
FloatField('Float', 'a_float'),
SelectField('Country', country_menu, 'country'),
PasswordField('Password', 'password',
required=True),
Checkbox('Active', 'active'),
)
buttons = Buttons((
Button('Save', 'save'),
Button('Cancel', 'cancel'),
))
fieldsets = (Fieldset(fields), )
ctx.locals.test_form = FieldsetForm('User details',
fieldsets,
buttons=buttons)
}}}
Render the form on the page:
{{{#!html