web/formfields.py
branchstable
changeset 9213 312062f53981
parent 9179 570208f74a84
child 9217 b4ac21bf6019
child 9278 a7894d5f00bb
--- a/web/formfields.py	Thu Aug 01 10:59:52 2013 +0200
+++ b/web/formfields.py	Thu Aug 01 13:55:11 2013 +0200
@@ -506,7 +506,7 @@
             if field is self:
                 try:
                     value = field.process_form_value(form)
-                    if value is None and field.required:
+                    if field.no_value(value) and field.required:
                         raise ProcessFormError(form._cw._("required field"))
                     yield field, value
                 except UnmodifiedField:
@@ -517,6 +517,11 @@
                 for field, value in field.process_posted(form):
                     yield field, value
 
+    @staticmethod
+    def no_value(value):
+        """return True if the value can be considered as no value for the field"""
+        return value is None
+
 
 class StringField(Field):
     """Use this field to edit unicode string (`String` yams type). This field
@@ -1165,6 +1170,12 @@
             eids.add(typed_eid)
         return eids
 
+    @staticmethod
+    def no_value(value):
+        """return True if the value can be considered as no value for the field"""
+        # value is None is the 'not yet ready value, consider the empty set
+        return value is not None and not value
+
 
 _AFF_KWARGS = uicfg.autoform_field_kwargs