Ticket #6652: field-on-validation-error.patch

File field-on-validation-error.patch, 1.1 KB (added by Daniele Varrazzo <piro@…>, 17 years ago)
  • newforms/util.py

     
    5050        return repr([force_unicode(e) for e in self])
    5151
    5252class ValidationError(Exception):
    53     def __init__(self, message):
     53    def __init__(self, message, field=None):
    5454        """
    5555        ValidationError can be passed any object that can be printed (usually
    5656        a string) or a list of objects.
    5757        """
     58        self.field = field
    5859        if isinstance(message, list):
    5960            self.messages = ErrorList([smart_unicode(msg) for msg in message])
    6061        else:
  • newforms/forms.py

     
    198198        try:
    199199            self.cleaned_data = self.clean()
    200200        except ValidationError, e:
    201             self._errors[NON_FIELD_ERRORS] = e.messages
     201            self._errors[e.field or NON_FIELD_ERRORS] = e.messages
    202202        if self._errors:
    203203            delattr(self, 'cleaned_data')
    204204
Back to Top