I've just finished writing and testing some new widgets, including a
RadioButtonList and Checkbox list. One thing came to mind with these
widgets and the SelectField widgets:the option list may need to be
created dynamically (e.g. during template insertion). I thought it
would be a good idea for the "options" argument to be either a list of
tuples(value, text, optional attrs) or a function returning same:

def get_categories():
    return [(cat.id, cat.name) for cat in model.Category.select()]

s = SelectField("categoryID", labeltext="Choose a category",
options=get_categories, validator=IntValidator())

c = CheckBoxList("categories", options=get_categories,
validator=ForEach(IntValidator()))

The "selected" or "checked" attributes are automatically set if they
match the input value(s).

Reply via email to