[Zope3-checkins] SVN: Zope3/branches/Zope-3.1/ Merged from trunk:

Jim Fulton jim at zope.com
Sat Jul 30 10:19:01 EDT 2005


Log message for revision 37596:
  Merged from trunk:
  
  r37595 | jim | 2005-07-30 10:12:18 -0400 (Sat, 30 Jul 2005) | 5 lines
  
  Fix #421: TextArea widgets didn't handle missing values correctly.
  
  For 3.2, we really need to reimplement the widgets so as not to depend
    on the overly complicated and brittle SimpleInputWidget.
  

Changed:
  U   Zope3/branches/Zope-3.1/doc/CHANGES.txt
  U   Zope3/branches/Zope-3.1/src/zope/app/form/browser/tests/test_textwidget.py
  U   Zope3/branches/Zope-3.1/src/zope/app/form/browser/textwidgets.py

-=-
Modified: Zope3/branches/Zope-3.1/doc/CHANGES.txt
===================================================================
--- Zope3/branches/Zope-3.1/doc/CHANGES.txt	2005-07-30 14:12:18 UTC (rev 37595)
+++ Zope3/branches/Zope-3.1/doc/CHANGES.txt	2005-07-30 14:19:01 UTC (rev 37596)
@@ -655,6 +655,9 @@
 
     Bug Fixes
 
+      - Fix #421: TextArea widgets didn't handle missing values
+        correctly.
+
       - Fix #384: Handling utility permissions
 
         When defining utilities in ZCML with permissions, checker

Modified: Zope3/branches/Zope-3.1/src/zope/app/form/browser/tests/test_textwidget.py
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/app/form/browser/tests/test_textwidget.py	2005-07-30 14:12:18 UTC (rev 37595)
+++ Zope3/branches/Zope-3.1/src/zope/app/form/browser/tests/test_textwidget.py	2005-07-30 14:19:01 UTC (rev 37596)
@@ -44,7 +44,8 @@
 
 from zope.app.testing.placelesssetup import setUp, tearDown
 from zope.app.form.browser.tests.test_browserwidget import BrowserWidgetTest
-from zope.app.form.browser.tests.test_browserwidget import SimpleInputWidgetTest
+from zope.app.form.browser.tests.test_browserwidget \
+     import SimpleInputWidgetTest
 
 class TextWidgetTest(SimpleInputWidgetTest):
     """Documents and tests the text widget.
@@ -371,7 +372,6 @@
     There was a bug that caused the value attribute to be set to
     'value' under these circumstances.
 
-    >>> from zope.publisher.browser import TestRequest
     >>> from zope.schema import TextLine
     >>> field = TextLine(__name__='foo', title=u'on',
     ...                  required=False, missing_value=u'')
@@ -399,7 +399,6 @@
     _error shouldn't be set due to an *internal* call to getInputValue
     when rendering.
 
-    >>> from zope.publisher.browser import TestRequest
     >>> from zope.schema import TextLine
     >>> field = TextLine(__name__='foo')
     >>> request = TestRequest(form={'field.foo': ''})
@@ -411,6 +410,34 @@
 
     """
 
+def test_text_area_works_with_missing_value():
+    """
+    >>> from zope.schema import Text
+    >>> field = Text(__name__='foo', title=u'on',
+    ...              required=False, missing_value=u'')
+    >>> request = TestRequest()
+    >>> widget = TextAreaWidget(field, request)
+    >>> def normalize(s):
+    ...   return '\\n  '.join(filter(None, s.split(' ')))
+
+    >>> print normalize( widget() )
+    <textarea
+      cols="60"
+      id="field.foo"
+      name="field.foo"
+      rows="15"
+      ></textarea>
+
+    >>> print normalize( widget.hidden() )
+    <input
+      class="hiddenType"
+      id="field.foo"
+      name="field.foo"
+      type="hidden"
+      value=""
+      />
+      """
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(TextWidgetTest),

Modified: Zope3/branches/Zope-3.1/src/zope/app/form/browser/textwidgets.py
===================================================================
--- Zope3/branches/Zope-3.1/src/zope/app/form/browser/textwidgets.py	2005-07-30 14:12:18 UTC (rev 37595)
+++ Zope3/branches/Zope-3.1/src/zope/app/form/browser/textwidgets.py	2005-07-30 14:19:01 UTC (rev 37596)
@@ -317,6 +317,9 @@
         if value:
             value = value.replace("\n", "\r\n")
             value = escape(value)
+        else:
+            value = u''
+            
         return value
 
     def __call__(self):



More information about the Zope3-Checkins mailing list