Ticket #5335: form_error_append.diff
File form_error_append.diff, 1.5 KB (added by , 17 years ago) |
---|
-
docs/newforms.txt
1387 1387 "field" (called ``__all__``, which you can access via the 1388 1388 ``non_field_errors()`` method if you need to. 1389 1389 1390 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. 1395 1390 1396 These methods are run in the order given above, one field at a time. That is, 1391 1397 for each field in the form (in the order they are declared in the form 1392 1398 definition), the ``Field.clean()`` method (or it's override) is run, then -
django/newforms/util.py
26 26 def as_text(self): 27 27 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()]) 28 28 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) 35 29 36 class ErrorList(list, StrAndUnicode): 30 37 """ 31 38 A collection of errors that knows how to display itself in various formats.