[Zope3-checkins] SVN: Zope3/trunk/ Bugfix: SimpleInputWidget used
to clear the widget's error as a side effect
Marius Gedminas
marius at pov.lt
Fri Apr 7 15:39:10 EDT 2006
Log message for revision 66654:
Bugfix: SimpleInputWidget used to clear the widget's error as a side effect
sometimes.
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/app/form/browser/tests/test_browserwidget.py
U Zope3/trunk/src/zope/app/form/browser/widget.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2006-04-07 16:47:41 UTC (rev 66653)
+++ Zope3/trunk/doc/CHANGES.txt 2006-04-07 19:39:09 UTC (rev 66654)
@@ -78,6 +78,9 @@
Bug Fixes
+ - SimpleInputWidget used to clear the widget's error as a side effect
+ sometimes.
+
- Fixed a bug in field prefix handling in formlib's setUp*Widgets.
- Fixed issue 573: @form.action(failure='name_of_method') didn't work.
Modified: Zope3/trunk/src/zope/app/form/browser/tests/test_browserwidget.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/tests/test_browserwidget.py 2006-04-07 16:47:41 UTC (rev 66653)
+++ Zope3/trunk/src/zope/app/form/browser/tests/test_browserwidget.py 2006-04-07 19:39:09 UTC (rev 66654)
@@ -31,7 +31,7 @@
from zope.i18n.gettextmessagecatalog import GettextMessageCatalog
from zope.i18n.translationdomain import TranslationDomain
from zope.publisher.browser import TestRequest
-from zope.schema import Text
+from zope.schema import Text, Int
from zope.app.form.browser.tests import support
import zope.app.form.browser.tests
@@ -191,7 +191,25 @@
widget = self._WidgetFactory(field, request)
self.assertEqual(widget._getFormValue(), u'def')
+ def test_getFormValue_preserves_errors(self):
+ field = Int(__name__ = 'foo', title = u"Foo Title", default=42)
+ request = TestRequest()
+ widget = self._WidgetFactory(field, request)
+ # Sometimes you want to set a custom error on a widget.
+ widget._error = 'my error'
+
+ # _getFormValue shouldn't replace it.
+ request.form['field.foo'] = u'barf!'
+ widget._getFormValue()
+ self.assertEquals(widget._error, 'my error')
+
+ # _getFormValue shouldn't clear it either
+ request.form['field.foo'] = 33
+ widget._getFormValue()
+ self.assertEquals(widget._error, 'my error')
+
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(Test))
Modified: Zope3/trunk/src/zope/app/form/browser/widget.py
===================================================================
--- Zope3/trunk/src/zope/app/form/browser/widget.py 2006-04-07 16:47:41 UTC (rev 66653)
+++ Zope3/trunk/src/zope/app/form/browser/widget.py 2006-04-07 19:39:09 UTC (rev 66654)
@@ -363,10 +363,12 @@
# necessary.
error = self._error
try:
- value = self.getInputValue()
- except InputErrors:
+ try:
+ value = self.getInputValue()
+ except InputErrors:
+ return self.request.form.get(self.name, self._missing)
+ finally:
self._error = error
- return self.request.form.get(self.name, self._missing)
else:
value = self._getDefault()
else:
More information about the Zope3-Checkins
mailing list