@view_config(renderer="templates/form.pt", name="select_readonly")
@demonstrate("Select Widget (read-only)")
def select_readonly(self):
from deform.widget import OptGroup
choices = (
("", "Select your favorite musician"),
OptGroup(
"Guitarists",
("page", "Jimmy Page"),
("hendrix", "Jimi Hendrix"),
),
OptGroup(
"Drummers",
("cobham", "Billy Cobham"),
("bonham", "John Bonham"),
),
)
class Schema(colander.Schema):
musician = colander.SchemaNode(
colander.String(),
widget=deform.widget.SelectWidget(
values=choices, readonly=True
),
)
multiple_musicians = colander.SchemaNode(
colander.Set(),
widget=deform.widget.SelectWidget(
values=choices, multiple=True, readonly=True
),
)
schema = Schema()
form = deform.Form(schema, buttons=("submit",))
appstruct = {
"musician": "cobham",
"multiple_musicians": ["cobham", "page"],
}
return self.render_form(form, appstruct=appstruct)