SVN: r24956 - trunk/quixote/form2

Neil Schemenauer <nascheme-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Thu, 19 Aug 2004 12:14:26 -0400
Newsgroups gmane.comp.web.quixote.cvs
Message-ID <[email protected]>
Author: nascheme
Date: 2004-08-19 12:14:03 -0400 (Thu, 19 Aug 2004)
New Revision: 24956

Modified:
   trunk/quixote/form2/widget.py
Log:
Fix a subtle bug in the form2 multiple select widget.  If nothing
is selected then the value should be None, not [None].


Modified: trunk/quixote/form2/widget.py
===================================================================
--- trunk/quixote/form2/widget.py	2004-08-19 15:39:29 UTC (rev 24955)
+++ trunk/quixote/form2/widget.py	2004-08-19 16:14:03 UTC (rev 24956)
@@ -403,18 +403,18 @@
                 options = [item[1] for item in doptions]
         self.options = options
 
-    def _parse_single_selection(self, parsed_key):
+    def _parse_single_selection(self, parsed_key, default=None):
         for value, description, key in self.options:
             if key == parsed_key:
                 return value
         else:
             if self.verify_selection:
                 self.error = "invalid value selected"
-                return None
+                return default
             elif self.options:
                 return self.options[0][0]
             else:
-                return None
+                return default
 
     def set_allowed_values(self, allowed_values, descriptions=None,
                            sort=False):
@@ -545,7 +545,12 @@
                                for value, description, key in self.options
                                if key in parsed_keys] or None
             else:
-                self.value = [self._parse_single_selection(parsed_keys)]
+                _marker = []
+                value = self._parse_single_selection(parsed_keys, _marker)
+                if value is _marker:
+                    self.value = None
+                else:
+                    self.value = [value]
         else:
             self.value = None