[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/form/browser/ input widgets for IBool fields should avoid calling themselves required

Fred L. Drake, Jr. fdrake at gmail.com
Thu Aug 17 11:55:53 EDT 2006


Log message for revision 69613:
  input widgets for IBool fields should avoid calling themselves required
  if there is no opportunity for entering the "no value" value
  

Changed:
  U   Zope3/trunk/src/zope/app/form/browser/boolwidgets.py
  U   Zope3/trunk/src/zope/app/form/browser/tests/test_checkboxwidget.py

-=-
Modified: Zope3/trunk/src/zope/app/form/browser/boolwidgets.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/boolwidgets.py	2006-08-17 15:45:33 UTC (rev 69612)
+++ Zope3/trunk/src/zope/app/form/browser/boolwidgets.py	2006-08-17 15:55:52 UTC (rev 69613)
@@ -37,6 +37,10 @@
     default = 0
     extra = ''
 
+    def __init__(self, context, request):
+        super(CheckBoxWidget, self).__init__(context, request)
+        self.required = False
+
     def __call__(self):
         """Render the widget to HTML."""
         value = self._getFormValue()
@@ -94,19 +98,27 @@
 
 def BooleanRadioWidget(field, request, true=_('on'), false=_('off')):
     vocabulary = SimpleVocabulary.fromItems( ((true, True), (false, False)) ) 
-    return RadioWidget(field, vocabulary, request)
+    widget = RadioWidget(field, vocabulary, request)
+    if field.required:
+        widget.required = False
+    return widget
 
 
 def BooleanSelectWidget(field, request, true=_('on'), false=_('off')):
     vocabulary = SimpleVocabulary.fromItems( ((true, True), (false, False)) )
     widget = SelectWidget(field, vocabulary, request)
     widget.size = 2
+    if field.required:
+        widget.required = False
     return widget
 
 
 def BooleanDropdownWidget(field, request, true=_('on'), false=_('off')):
     vocabulary = SimpleVocabulary.fromItems( ((true, True), (false, False)) )
-    return DropdownWidget(field, vocabulary, request)
+    widget = DropdownWidget(field, vocabulary, request)
+    if field.required:
+        widget.required = False
+    return widget
 
 
 _msg_true = _("True")

Modified: Zope3/trunk/src/zope/app/form/browser/tests/test_checkboxwidget.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/tests/test_checkboxwidget.py	2006-08-17 15:45:33 UTC (rev 69612)
+++ Zope3/trunk/src/zope/app/form/browser/tests/test_checkboxwidget.py	2006-08-17 15:55:52 UTC (rev 69613)
@@ -163,7 +163,13 @@
         del self._widget.request.form['field.foo.used']
         self.assertRaises(MissingInputError, self._widget.getInputValue)
 
+    def test_required(self):
+        # checkbox widgets are never required, since there's no way to
+        # set it to "no value"
+        self.failIf(self._widget.required)
+        self.assert_(self._widget.context.required)
 
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(CheckBoxWidgetTest),



More information about the Zope3-Checkins mailing list