@view_config(renderer="templates/form.pt", name="selectize_with_optgroup")
@demonstrate("Selectize Widget (with optgroup)")
def selectize_with_optgroup(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.SelectizeWidget(
values=choices,
attributes={
"placeholder": "Select...",
},
),
)
schema = Schema()
form = deform.Form(schema, buttons=("submit",))
return self.render_form(form)