Ignore:
Timestamp:
23 Dec 2011, 10:49:11 (13 years ago)
Author:
uli
Message:

Provide a better fix for the required field problem of
phonewidget. There are still issues with default values left open.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/widgets/phonewidget.py

    r7428 r7439  
    3030"""
    3131import re
     32import copy
    3233from waeup.sirp import MessageFactory as _
    3334from zope import schema
     
    6667        constraint=re.compile(r'^[0-9]{3,}$').search,
    6768        required=True)
    68 
    6969
    7070class PhoneWidgetData(object):
     
    129129        """
    130130        value = self.context.query(self.context.context)
    131         adapters = {}
    132         adapters[IPhoneData] = PhoneWidgetData(self, value)
     131        # we have to modify the adapter according to our own
     132        # 'required' state. Some ugly workaround
     133        adapter = copy.deepcopy(IPhoneData)
     134        for name in 'country', 'area', 'extension':
     135            adapter[name].required = self.required
     136        adapters = {adapter: PhoneWidgetData(self, value)}
    133137        self.widgets = form.setUpEditWidgets(
    134138            form.FormFields(IPhoneData),
     
    164168        self._error = None
    165169        try:
    166             return u'-'.join((
     170            result = u'-'.join((
    167171                self.widgets['country'].getInputValue(),
    168172                self.widgets['area'].getInputValue(),
    169173                self.widgets['extension'].getInputValue() ))
     174            return result
     175        except TypeError:
     176            if self.required:
     177                return self._missing
     178            return None
    170179        except ValueError, v:
    171180            self._error = WidgetInputError(
     
    173182            raise self._error
    174183        except WidgetInputError, e:
    175             # Subwidgets require input. We have to work around that if
    176             # the parent widget does not require input.
    177             missing = isinstance(e.errors, RequiredMissing)
    178             missing = missing or isinstance(e, MissingInputError)
    179             if not self.required and missing:
    180                 return self._missing
    181184            self._error = e
    182185            raise e
Note: See TracChangeset for help on using the changeset viewer.