Ticket #5335: form_error_append.diff

File form_error_append.diff, 1.5 KB (added by Thomas Güttler <hv@…>, 13 years ago)
  • docs/newforms.txt

    13871387      "field" (called ``__all__``, which you can access via the
    13881388      ``non_field_errors()`` method if you need to.
     1391      Instead of raising an ValidationError inside ``Form.clean()``,
     1392      you can add an error message with
     1393      ``self.errors.append(fieldname, message)``. This way the error message
     1394      will be displayed near the given field.
    13901396These methods are run in the order given above, one field at a time.  That is,
    13911397for each field in the form (in the order they are declared in the form
    13921398definition), the ``Field.clean()`` method (or it's override) is run, then
  • django/newforms/util.py

    2626    def as_text(self):
    2727        return u'\n'.join([u'* %s\n%s' % (k, u'\n'.join([u'  * %s' % smart_unicode(i) for i in v])) for k, v in self.items()])
     29    def append(self, name, message):
     30        errorlist=self.get(name)
     31        if errorlist==None:
     32            errorlist=ErrorList()
     33            self[name]=errorlist
     34        errorlist.append(message)
    2936class ErrorList(list, StrAndUnicode):
    3037    """
    3138    A collection of errors that knows how to display itself in various formats.
Back to Top