Opened 9 months ago
Last modified 9 months ago
#35243 closed New feature
Add easy access to error codes in forms — at Version 2
Reported by: | Christophe Henry | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 5.0 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
The ValidationError
has a
code
field that can be used in views to determined what exactly failed during form validation. Unfortunately, the list of error codes in not easily accessible from form. Actually, if I want to recover the
ValidationError.code
s for a form's particular field, I must write the following:
error_codes = [err.code for err in form.errors.get("field", ErrorList()).data]
I propose to add a error_codes
to the
Form
class as follows:
@property def errors_codes(self): """Return the list of error codes for each field of this form.""" if self._errors_codes is None: self._errors_codes = { field: [error.code for error in errors.data if error.code] for field, errors in self.errors.items() } return self._errors_codes
Change History (2)
comment:1 by , 9 months ago
Component: | Uncategorized → Forms |
---|---|
Type: | Uncategorized → New feature |
comment:2 by , 9 months ago
Description: | modified (diff) |
---|
Note:
See TracTickets
for help on using tickets.