Opened 2 months ago
Closed 2 months ago
#35755 closed Bug (fixed)
Help text for hidden fields is visible in admin fieldsets
Reported by: | Richard Laager | Owned by: | Richard Laager |
---|---|---|---|
Component: | contrib.admin | Version: | 4.2 |
Severity: | Normal | Keywords: | |
Cc: | Tom Carrick | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | yes |
Description
This is present in 4.2 through git main.
If a field is hidden, its help_text shows.
This regressed in commit 96a598356a9ea8c2c05b22cadc12e256a3b295fd:
https://github.com/django/django/commit/96a598356a9ea8c2c05b22cadc12e256a3b295fd
from PR 16161:
https://github.com/django/django/pull/16161
This happened because the <div class="help"> is now after, as opposed to inside, the <div> that gets class "hidden".
There are two possible fixes:
A) Do not output the help div at all:
--- a/django/contrib/admin/templates/admin/includes/fieldset.html +++ b/django/contrib/admin/templates/admin/includes/fieldset.html @@ -26,7 +26,7 @@ {% endif %} {% endif %} </div> - {% if field.field.help_text %} + {% if field.field.help_text and not field.field.is_hidden %} <div class="help"{% if field.field.id_for_label %} id="{{ field.field.id_for_label }}_helptext"{% endif %}> <div>{{ field.field.help_text|safe }}</div> </div>
B) Set "hidden" on the help div:
--- a/django/contrib/admin/templates/admin/includes/fieldset.html +++ b/django/contrib/admin/templates/admin/includes/fieldset.html @@ -27,7 +27,7 @@ {% endif %} </div> {% if field.field.help_text %} - <div class="help"{% if field.field.id_for_label %} id="{{ field.field.id_for_label }}_helptext"{% endif %}> + <div class="help{% if field.field.is_hidden %} hidden{% endif %}"{% if field.field.id_for_label %} id="{{ field.field.id_for_label }}_helptext"{% endif %}> <div>{{ field.field.help_text|safe }}</div> </div> {% endif %}
Either fix works. I'm just not sure stylistically which one you want.
Change History (5)
comment:1 by , 2 months ago
Easy pickings: | set |
---|---|
Has patch: | set |
comment:2 by , 2 months ago
Cc: | added |
---|---|
Has patch: | unset |
Summary: | Regression: Help text for hidden fields shows → Help text for hidden fields is visible in admin fieldsets |
Triage Stage: | Unreviewed → Accepted |
UI/UX: | set |
comment:3 by , 2 months ago
Has patch: | set |
---|---|
Owner: | set to |
Status: | new → assigned |
comment:4 by , 2 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
Thank you Richard! Would you like to prepare a PR?
On what is the "right" way to fix it, I think either approach works, I would perhaps add the "hidden" class.
As a rough idea of a regression test, something like this might work (depending on the approach):
tests/admin_inlines/models.py
)tests/admin_inlines/tests.py