Re: [Zope3-Users] Using a multicheckboxwidget instead of a multiselectsetwidget

2005-06-23 Thread Stephan Richter
On Wednesday 08 June 2005 10:43, Jan-Wijbrand Kolman wrote:
> In mywidgets.py:
>
>   from zope.app.form.browser import MultiCheckBoxWidget as
> MultiCheckBoxWidget_ def MultiCheckBoxWidget(field, request):
>     vocabulary = field.value_type.vocabulary
>     return MultiCheckBoxWidget_(field, vocabulary, request)
>
> In the configure.zcml:
>
>        name="add_foo"
>     label="Add Foo"
>     schema=".interfaces.IFoo"
>     fields="filetypes"
>     content_factory=".foo.Foo"
>     template="foo.pt"
>     permission="zope.Public"
>   >
>        field="filetypes"
>     class=".mywidgets.MultiCheckBoxWidget"
>   />
>   
>
> Probably there're better ways to do this...?

No, this is a good solution and should be incorporated into zope.app.form 
somehow.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users


Re: [Zope3-Users] Using a multicheckboxwidget instead of a multiselectsetwidget

2005-06-08 Thread Jan-Wijbrand Kolman
Jan-Wijbrand Kolman wrote:
> I have a interface defined for some content type, say IFoo. IFoo defines one
> schema field:
> 
>   _filetypes = SimpleVocabulary.fromValues(('fropple', 'frepple', 'froople'))
> 
>   class IFoo(Interface):
> 
> filetypes = Set(
>   title=u'',
>   required=False,
>   value_type=Choice(vocabulary=_filetypes),
>   )
> 
> By default, the edit widget that is used for this field, is a
> zope.app.form.browser.MultiSelectSetWidget, which will render a  multiple="multiple">... element.
> 
> Now I'd like to use multiple checkboxes instead, since the number of choices 
> for
> this field will never exceed 3 or 4 anyway. I thought to accomplish this by
> configuring the MultiCheckBoxWidget for this, in the addform registration for
> the Foo content type:
> 
>name="add_foo"
> label="Add Foo"
> schema=".interfaces.IFoo"
> fields="filetypes"
> content_factory=".foo.Foo"
> template="foo.pt"
> permission="zope.Public"
>   >
>field="filetypes"
> class="zope.app.form.browser.itemswidgets.MultiCheckBoxWidget"
>   />
>   
> 
> This however doesn't work and I get the following traceback (pasted the last
> couple of lines):
> 
>   File "...zope31/src/zope/app/form/browser/add.py", line 47, in _setUpWidgets
> setUpWidgets(self, self.schema, IInputWidget, names=self.fieldNames)
>   File "...zope31/src/zope/app/form/utility.py", line 153, in setUpWidgets
> context=context)
>   File "...zope31/src/zope/app/form/utility.py", line 101, in setUpWidget
> widget = widget(field.bind(context), view.request)
>   File "...zope31/src/zope/app/form/__init__.py", line 97, in __call__
> instance = self._widget_factory(*args)
> TypeError: __init__() takes exactly 4 arguments (3 given)
> 
> Now, I do indeed see the __init__ for the MultiCheckboxWidget class (well, one
> of its baseclasses actually) expects a vocabulary argument. How can I make 
> sure
> this widget gets all the info it needs? Maybe I just don't see the obvious, 
> but
> can anyone provide some hint in the right direction?

Answering myself. I have a workaround:

In mywidgets.py:

  from zope.app.form.browser import MultiCheckBoxWidget as MultiCheckBoxWidget_
  def MultiCheckBoxWidget(field, request):
vocabulary = field.value_type.vocabulary
return MultiCheckBoxWidget_(field, vocabulary, request)

In the configure.zcml:

  
  
  

Probably there're better ways to do this...?


kind regards,
jw

-- 
Jan-Wijbrand Kolman
[EMAIL PROTECTED]
___
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users