[Zope3-Users] MultiCheckBoxWidget and formlib
Tom Dossis
td at yoma.com.au
Fri May 26 20:01:10 EDT 2006
Mats Nordgren wrote:
> Could anyone give me a hint on setting up a MultiCheckBoxWidget with
> formlib?
>
>
> This is what I got:
>
> class IMySchema(Interface):
> multichoice = Set(
> title=_('Pick one or many'),
> value_type = Choice(values=['one', 'two', 'three']))
>
> class MyEditForm(form.EditForm):
> form_fields = form.Fields(IMySchema)
> form_fields['multichoice'].custom_widget = ????????
>
>
> What in the world do I do to get this to work?
I've done something similar along the lines of...
class IMySchema(Interface):
multichoice = Set(
title=_('Pick one or many'),
value_type=SimpleVocabulary.fromItems([
(_("One"), "one"),
(_("Two"), "two"),
(_("Three", "three"),
])
Maybe try zope.app.form.browser.MultiSelectWidget ..
It requires 3 args in its constructor which you can wrap for formlib, e.g.
class MyMultiSelectWidget(MultiSelectWidget):
def __init__(self, field, request):
super(MyMultiSelectWidget, self).__init__(
field, field.value_type.vocabulary, request)
Then ..
form_fields['multichoice'].custom_widget=MyMultiSelectWidget
You could also look at the alternative widget..
zope.app.form.browser.itemswidgets.MultiCheckBoxWidget
More information about the Zope3-users
mailing list