From 97ef622a783faff789b8af33bfaf2240733beb5f Mon Sep 17 00:00:00 2001 From: sanjeevholla26 Date: Mon, 9 Sep 2024 18:32:06 +0530 Subject: [PATCH] Refs #35706 -- Added an instance variable to track whether field errors exist --- django/contrib/admin/options.py | 1 + .../admin/templates/admin/change_form.html | 36 ++++++++++++++----- django/forms/forms.py | 3 +- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 6d5c0708a3..22374be658 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -1940,6 +1940,7 @@ class ModelAdmin(BaseModelAdmin): "inline_admin_formsets": inline_formsets, "errors": helpers.AdminErrorList(form, formsets), "preserved_filters": self.get_preserved_filters(request), + "field_errors_exist": form._field_errors_exist, } # Hide the "Save" and "Save and continue" buttons if "Save as New" was diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html index 298fe91e8d..2ad2b7e103 100644 --- a/django/contrib/admin/templates/admin/change_form.html +++ b/django/contrib/admin/templates/admin/change_form.html @@ -25,27 +25,27 @@ {% block pretitle %} {% if errors %} -

- {% blocktranslate count counter=errors|length %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktranslate %} -

- - {{ adminform.form.non_field_errors }} - -
-

The following fields have errors

+ {% endif %} {% endblock %} @@ -85,6 +85,24 @@ {% block submit_buttons_bottom %}{% submit_row %}{% endblock %} {% block admin_change_form_document_ready %} +{% if errors %} + +{% endif %} +