[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Forms/Views/Browser - Widget.py:1.15

Jim Fulton jim@zope.com
Thu, 19 Dec 2002 14:53:29 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Forms/Views/Browser
In directory cvs.zope.org:/tmp/cvs-serv21802

Modified Files:
	Widget.py 
Log Message:
  revision 1.14.2.2
  date: 2002/12/12 16:09:09;  author: jim;  state: Exp;  lines: +6 -2
  Fixed a bug in _showData (used to get data to be displayed in an edit
  widget). We failed to use field defaults when there was no initial
  data pr request data.

  revision 1.14.2.1
  date: 2002/12/12 15:16:50;  author: jim;  state: Exp;  lines: +17 -2
  Changed the widget haveData method to run the conversion api to make
  sure that there is non-missing data, not just form data.


=== Zope3/lib/python/Zope/App/Forms/Views/Browser/Widget.py 1.14 => 1.15 ===
--- Zope3/lib/python/Zope/App/Forms/Views/Browser/Widget.py:1.14	Wed Dec 11 08:52:48 2002
+++ Zope3/lib/python/Zope/App/Forms/Views/Browser/Widget.py	Thu Dec 19 14:53:28 2002
@@ -44,7 +44,9 @@
     _missing = None
 
     def haveData(self):
-        return (self.name) in self.request.form
+        if (self.name) in self.request.form:
+            return self._convert(self.request[self.name]) is not None
+        return False
 
     def getData(self, optional=0):
         field = self.context
@@ -87,8 +89,12 @@
         return value
 
     def _showData(self):
-        if (self._data is None) and self.haveData():
-            data = self.getData(1)
+
+        if (self._data is None):
+            if self.haveData():
+                data = self.getData(1)
+            else:
+                data = self.context.default
         else:
             data = self._data
 
@@ -196,6 +202,11 @@
     style = "width:100%"
     __values = None
 
+    def _convert(self, value):
+        if self.context.min_length and not value:
+            return None
+        return value
+
     def __init__(self, *args):
         super(TextWidget, self).__init__(*args)
         
@@ -264,6 +275,9 @@
 class Bytes:
 
     def _convert(self, value):
+        if self.context.min_length and not value:
+            return None
+
         value = super(Bytes, self)._convert(value)
         if type(value) is unicode:
             value = value.encode('ascii')
@@ -293,6 +307,11 @@
     height = 15
     extra=""
     style="width:100%"
+
+    def _convert(self, value):
+        if self.context.min_length and not value:
+            return None
+        return value
     
     def __call__(self):
         'See Zope.App.Forms.Views.Browser.IBrowserWidget.IBrowserWidget'