web/formfields.py
changeset 9217 b4ac21bf6019
parent 9205 ea32e964fbf8
parent 9213 312062f53981
child 9257 ce338133c92c
equal deleted inserted replaced
9205:ea32e964fbf8 9217:b4ac21bf6019
   504         """
   504         """
   505         for field in self.actual_fields(form):
   505         for field in self.actual_fields(form):
   506             if field is self:
   506             if field is self:
   507                 try:
   507                 try:
   508                     value = field.process_form_value(form)
   508                     value = field.process_form_value(form)
   509                     if value is None and field.required:
   509                     if field.no_value(value) and field.required:
   510                         raise ProcessFormError(form._cw._("required field"))
   510                         raise ProcessFormError(form._cw._("required field"))
   511                     yield field, value
   511                     yield field, value
   512                 except UnmodifiedField:
   512                 except UnmodifiedField:
   513                     continue
   513                     continue
   514             else:
   514             else:
   515                 # recursive function: we might have compound fields
   515                 # recursive function: we might have compound fields
   516                 # of compound fields (of compound fields of ...)
   516                 # of compound fields (of compound fields of ...)
   517                 for field, value in field.process_posted(form):
   517                 for field, value in field.process_posted(form):
   518                     yield field, value
   518                     yield field, value
       
   519 
       
   520     @staticmethod
       
   521     def no_value(value):
       
   522         """return True if the value can be considered as no value for the field"""
       
   523         return value is None
   519 
   524 
   520 
   525 
   521 class StringField(Field):
   526 class StringField(Field):
   522     """Use this field to edit unicode string (`String` yams type). This field
   527     """Use this field to edit unicode string (`String` yams type). This field
   523     additionaly support a `max_length` attribute that specify a maximum size for
   528     additionaly support a `max_length` attribute that specify a maximum size for
  1167                 else:
  1172                 else:
  1168                     form._cw.data['pending_others'].add( (form, self) )
  1173                     form._cw.data['pending_others'].add( (form, self) )
  1169                 return None
  1174                 return None
  1170             eids.add(typed_eid)
  1175             eids.add(typed_eid)
  1171         return eids
  1176         return eids
       
  1177 
       
  1178     @staticmethod
       
  1179     def no_value(value):
       
  1180         """return True if the value can be considered as no value for the field"""
       
  1181         # value is None is the 'not yet ready value, consider the empty set
       
  1182         return value is not None and not value
  1172 
  1183 
  1173 
  1184 
  1174 _AFF_KWARGS = uicfg.autoform_field_kwargs
  1185 _AFF_KWARGS = uicfg.autoform_field_kwargs
  1175 
  1186 
  1176 def guess_field(eschema, rschema, role='subject', req=None, **kwargs):
  1187 def guess_field(eschema, rschema, role='subject', req=None, **kwargs):