Adding Form.has_error() to easily check if a given error has happened.
|Reported by:||loic84||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Since #17413, it's possible to know, not only if a field has errors, but also what these errors are.
I propose that we add an API to easily check if a given error has happened.
This would enable logic like this in the view:
if form.has_error('email', 'not_verified'): context['email_not_verified'] = True
When a given error happens, I often want to display HTML that describes how to resolve the issue, (usually with links to the relevant sections in the docs which in turn require url reversing); stuffing these in the error message is neither clean (HTML belongs to the templates), nor practical. Following a given error, one may also want to perform actions that typically belongs to the views, like using the message framework.
Change History (4)
comment:1 Changed 18 months ago by loic84
- Has patch set
- Needs documentation set
- Needs tests unset
- Patch needs improvement set