[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form - widget.py:1.37

Richard Jones richard@commonground.com.au
Fri, 11 Jul 2003 22:47:42 -0400


Update of /cvs-repository/Zope3/src/zope/app/browser/form
In directory cvs.zope.org:/tmp/cvs-serv26157/src/zope/app/browser/form

Modified Files:
	widget.py 
Log Message:
Sequence value_types argument is now value_type (ie. a single Field type)
Dict key_types and value_types are also changed to key_type and value_type.
[having multiple value/key types makes no sense and actually makes widgets
extraordinarily difficult to implement (read: approaching impossible :)]


=== Zope3/src/zope/app/browser/form/widget.py 1.36 => 1.37 ===
--- Zope3/src/zope/app/browser/form/widget.py:1.36	Fri Jul 11 21:28:59 2003
+++ Zope3/src/zope/app/browser/form/widget.py	Fri Jul 11 22:47:07 2003
@@ -948,8 +948,8 @@
     def __call__(self):
         """Render the widget
         """
-        # XXX we really shouldn't allow value_types of None
-        if self.context.value_types is None:
+        # XXX we really shouldn't allow value_type of None
+        if self.context.value_type is None:
             return ''
 
         if not self._sequence_generated:
@@ -975,7 +975,7 @@
 
         # generate each widget from items in the _sequence - adding a
         # "remove" button for each one
-        field = self.context.value_types[0]
+        field = self.context.value_type
         for i in range(num_items):
             value = sequence[i]
             r('<tr><td>')
@@ -1015,7 +1015,7 @@
         num_items = len(sequence)
 
         # generate hidden fields for each value
-        field = self.context.value_types[0]
+        field = self.context.value_type
         s = ''
         for i in range(num_items):
             value = sequence[i]
@@ -1040,6 +1040,9 @@
         # XXX enforce required
         if not self._sequence_generated:
             self._generateSequenceFromRequest()
+        # validate the input values
+        for value in self._sequence:
+            self.context.value_type.validate(value)
         return self._type(self._sequence)
 
     def haveData(self):
@@ -1071,11 +1074,11 @@
         adding = False
         removing = []
         subprefix = re.compile(r'(\d+)\.(.+)')
-        if self.context.value_types is None:
+        if self.context.value_type is None:
             self._sequence = []
             self._sequence_generated = True
             return
-        field = self.context.value_types[0]
+        field = self.context.value_type
 
         # pre-populate 
         found = {}
@@ -1110,7 +1113,6 @@
                 widget = zapi.getView(field, 'edit', self.request, self.context)
                 widget.setPrefix('%s.%d.'%(prefix, i))
                 value = widget.getData()
-                field.validate(value)
                 found[i] = value
 
         # remove the indicated indexes