Back to index

plone3  3.1.7
multicheckboxwidget.py
Go to the documentation of this file.
00001 from zope.app.form.browser.widget import renderElement
00002 from zope.app.form.browser import MultiCheckBoxWidget as BaseWidget
00003 
00004 
00005 class MultiCheckBoxWidget(BaseWidget):
00006     """Provide a list of checkboxes that provide the choice for the list,
00007        with a <label> for accessibility"""
00008 
00009     orientation = "vertical"
00010 
00011     _joinButtonToMessageTemplate = u"%s %s"
00012     
00013     def renderItem(self, index, text, value, name, cssClass):
00014         id = '%s.%s' % (name, index)
00015         elem = renderElement('input',
00016                              type="checkbox",
00017                              cssClass=cssClass,
00018                              name=name,
00019                              id=id,
00020                              value=value)
00021 
00022         label = renderElement('label',
00023                               extra= u"for=%s" % id,
00024                               contents=text)
00025 
00026         return self._joinButtonToMessageTemplate %(elem, label)
00027 
00028     def renderSelectedItem(self, index, text, value, name, cssClass):
00029         id = '%s.%s' % (name, index)
00030         elem = renderElement('input',
00031                              type="checkbox",
00032                              cssClass=cssClass,
00033                              name=name,
00034                              id=id,
00035                              value=value,
00036                              checked="checked")
00037 
00038         label = renderElement('label',
00039                               extra= u"for=%s" % id,
00040                               contents=text)
00041 
00042         return self._joinButtonToMessageTemplate %(elem, label)