[Zope3-Users] z3c.form, checkboxes for Bool fields

Andreas Reuleaux reuleaux at web.de
Sat Sep 1 17:19:54 EDT 2007


In my interface I have Bool fields, say e. g. for invitation

  class IAdr(Interface)
    ...
    invitation = Bool(
	    title=u'Invitation',
	    description=u'Invitation?',
	    required=False
	    )
     ...

Now when rendering the following edit-form

  class AdrEditForm(form.EditForm):
      fields = field.Fields(IAdr)
      ...

I get radio-boxes for invitation like so:

  (*) yes ( ) no

(by the way: this can also been seen in z3c.formdemo on the
"All widgets" page widgets.html)

Well nice - after all this reflects the behaviour of boolean
values: they can be either yes (True) or no (False).

Actually I preferred formlibs behaviour of rendering checkboxes
for Bools though, something like:

  [v]

I. e. a single checkbox that can either be checked [v] or not [ ]
should suffice for a boolean value. - This is shorter than
the radio buttons and just as good.

Now I was hoping that this was implemented in z3c.form.browser.checkbox
already:


  class AdrEditForm(form.EditForm):
      fields = field.Fields(IAdr)

      def MyFieldWidget(field, req):
        return widget.FieldWidget(field, checkbox.CheckBoxWidget(req))

      fields['invitation'].widgetFactory = MyFieldWidget


However I get *two* checkboxes now

  [ ] yes [ ] no

for the one boolean field invitation - that's not exactly what
I was looking for: *one* checkbox should be enough for a Bool field
- and what should happen by the way, if I check both boxes  
([v] yes [v] no)?

I think there should be an easy way to do this. This is very
common after all. - Any hints? Have I overlooked something?

-Andreas

 


More information about the Zope3-users mailing list