Opened 15 months ago

Closed 14 months ago

Last modified 14 months ago

#34383 closed Bug (fixed)

Layout error in Admin when using help_text

Reported by: Antonio Candido Nazareth junior Owned by: Tom Carrick
Component: Template system Version: 4.2
Severity: Release blocker Keywords: help_text
Cc: Tom Carrick Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Antonio Candido Nazareth junior)

I'm using Django 4.2b1 and found a problem with the Django admin layout when I use the help_text in model admin. The help_text in the Admin form appears on a separate line and breaks the alignment of the fields. This happens in every browser I've tested.

Create a model with two or more fields that have help_text defined with a size larger than the field name. Register this model in admin.py with ModelAdmin and put them on the same line using fieldsets giving name to the line. Access the edit page of this model in Django admin and observe the layout.
Expected result:

The help_text should appear below the corresponding field, without affecting the alignment of the other fields.
https://code.djangoproject.com/attachment/ticket/34383/4.2b1.png

Attachments (3)

4.2b1.png (25.6 KB ) - added by Antonio Candido Nazareth junior 15 months ago.
Print erro on Django Version 4.2b1
4.1.7.png (26.1 KB ) - added by Antonio Candido Nazareth junior 15 months ago.
Print on Django Version 4.1.5 its ok
bug.jpg (147.1 KB ) - added by Antonio Candido Nazareth junior 14 months ago.
Error breaking line with two or more columns with help_text

Download all attachments as: .zip

Change History (14)

by Antonio Candido Nazareth junior, 15 months ago

Attachment: 4.2b1.png added

Print erro on Django Version 4.2b1

by Antonio Candido Nazareth junior, 15 months ago

Attachment: 4.1.7.png added

Print on Django Version 4.1.5 its ok

comment:1 by Antonio Candido Nazareth junior, 15 months ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 15 months ago

Resolution: needsinfo
Status: newclosed

Hi, I don't think you've explained the issue in enough detail to confirm a bug in Django. Do you have any custom templates? Please reopen the ticket if you can debug your issue and provide a sample minimal project that reproduces it.

by Antonio Candido Nazareth junior, 14 months ago

Attachment: bug.jpg added

Error breaking line with two or more columns with help_text

comment:3 by Antonio Candido Nazareth junior, 14 months ago

Resolution: needsinfo
Status: closednew

Steps to reproduce the error:
Create model new:

app.new.models.py

from django.db import models

class Favi(models.Model):
    faviNumero = models.CharField(max_length=20,help_text='Data incluindo o Horário do término da viagem')    
    matricula1 = models.CharField(max_length=50,help_text='Data incluindo o Horário do término da viagem')    
    matricula3 = models.CharField(max_length=50,help_text='Data incluindo o Horário do término da viagem')    
    matricula2 = models.CharField(max_length=50,help_text='Data incluindo o Horário do término da viagem')    
    matricula = models.CharField(max_length=50,help_text='Data incluindo o Horário do término da viagem')    
    objetivo = models.TextField(verbose_name='Objetivo', help_text='DESCRIÇÃO OBJETIVA DO SERVIÇO A SER EXECUTADO')
    
    periodoInicio = models.DateTimeField(verbose_name='Início',help_text='Data incluindo o Horário de início da viagem')
    periodoTermino = models.DateTimeField(verbose_name='Término',help_text='Data incluindo o Horário do término da viagem')

app.new.admin.py

from django.contrib import admin
from new.models import Favi

# Register your models here.
class FilterFaviAdmin(admin.ModelAdmin):
    fieldsets = [
    (None,                  {'fields':[('faviNumero','matricula1','matricula3'),'objetivo',('periodoInicio','periodoTermino'),('matricula2','matricula',),]}),    
    ]
admin.site.register(Favi,FilterFaviAdmin)

Result appears broken layout with help text as image below installed django pre version 4.2b1

https://code.djangoproject.com/attachment/ticket/34383/bug.jpg
works on django version 4.1.7

comment:4 by Mariusz Felisiak, 14 months ago

Cc: Tom Carrick added
Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

Thanks for details!

Regression in 96a598356a9ea8c2c05b22cadc12e256a3b295fd.

comment:5 by Mariusz Felisiak, 14 months ago

I tried to fix this, it's much better (but not perfect, you can see minor issues on the "Change user" view) with the following diff:

  • django/contrib/admin/static/admin/css/forms.css

    diff --git a/django/contrib/admin/static/admin/css/forms.css b/django/contrib/admin/static/admin/css/forms.css
    index 3cd87ef476..e73831a83f 100644
    a b form ul.inline li {  
    7272/* ALIGNED FIELDSETS */
    7373
    7474.aligned label {
    75     display: block;
     75    display: inline-block;
    7676    padding: 4px 10px 0 0;
    7777    width: 160px;
    7878    word-wrap: break-word;
    form ul.inline li {  
    114114}
    115115
    116116form .aligned ul {
    117     margin-left: 160px;
     117    margin-left: 166px;
    118118    padding-left: 10px;
    119119}
    120120
    form .aligned div.radiolist {  
    127127form .aligned p.help,
    128128form .aligned div.help {
    129129    margin-top: 0;
    130     margin-left: 160px;
     130    margin-left: 166px;
    131131    padding-left: 10px;
    132132}
    133133
    form .aligned table p {  
    191191}
    192192
    193193fieldset .fieldBox {
    194     float: left;
    195194    margin-right: 20px;
    196195}
    197196
  • django/contrib/admin/static/admin/css/widgets.css

    diff --git a/django/contrib/admin/static/admin/css/widgets.css b/django/contrib/admin/static/admin/css/widgets.css
    index 572dc0a500..c81bcf654d 100644
    a b ul.timelist, .timelist li {  
    578578
    579579/* RELATED WIDGET WRAPPER */
    580580.related-widget-wrapper {
    581     float: left;       /* display properly in form rows with multiple fields */
    582581    overflow: hidden;  /* clear floated contents */
    583582}
    584583
  • django/contrib/admin/templates/admin/includes/fieldset.html

    diff --git a/django/contrib/admin/templates/admin/includes/fieldset.html b/django/contrib/admin/templates/admin/includes/fieldset.html
    index 5953a5ad3d..0d398d1de1 100644
    a b  
    66    {% for line in fieldset %}
    77        <div class="form-row{% if line.fields|length == 1 and line.errors %} errors{% endif %}{% if not line.has_visible_field %} hidden{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}">
    88            {% if line.fields|length == 1 %}{{ line.errors }}{% endif %}
    9             {% for field in line %}
    10                 <div{% if not line.fields|length == 1 %} class="fieldBox{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}>
    11                     {% if not line.fields|length == 1 and not field.is_readonly %}{{ field.errors }}{% endif %}
    12                     {% if field.is_checkbox %}
    13                         {{ field.field }}{{ field.label_tag }}
    14                     {% else %}
    15                         {{ field.label_tag }}
    16                         {% if field.is_readonly %}
    17                             <div class="readonly">{{ field.contents }}</div>
    18                         {% else %}
    19                             {{ field.field }}
    20                         {% endif %}
    21                     {% endif %}
    22                 </div>
    23                 {% if field.field.help_text %}
    24                     <div class="help"{% if field.field.id_for_label %} id="{{ field.field.id_for_label }}_helptext"{% endif %}>
    25                         <div>{{ field.field.help_text|safe }}</div>
    26                     </div>
    27                 {% endif %}
    28             {% endfor %}
     9            <div>
     10              {% for field in line %}
     11                <div>
     12                  <div{% if not line.fields|length == 1 %} class="fieldBox{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}>
     13                      {% if not line.fields|length == 1 and not field.is_readonly %}{{ field.errors }}{% endif %}
     14                      {% if field.is_checkbox %}
     15                          {{ field.field }}{{ field.label_tag }}
     16                      {% else %}
     17                          {{ field.label_tag }}
     18                          {% if field.is_readonly %}
     19                              <div class="readonly">{{ field.contents }}</div>
     20                          {% else %}
     21                              {{ field.field }}
     22                          {% endif %}
     23                      {% endif %}
     24                  </div>
     25                  {% if field.field.help_text %}
     26                      <div class="help"{% if field.field.id_for_label %} id="{{ field.field.id_for_label }}_helptext"{% endif %}>
     27                          <div>{{ field.field.help_text|safe }}</div>
     28                      </div>
     29                  {% endif %}
     30                  </div>
     31              {% endfor %}
     32            </div>
    2933        </div>
    3034    {% endfor %}
    3135</fieldset>
  • django/contrib/auth/templates/auth/widgets/read_only_password_hash.html

    diff --git a/django/contrib/auth/templates/auth/widgets/read_only_password_hash.html b/django/contrib/auth/templates/auth/widgets/read_only_password_hash.html
    index c73042b18f..447f55a99b 100644
    a b  
    1 <div{% include 'django/forms/widgets/attrs.html' %}>
     1<span{% include 'django/forms/widgets/attrs.html' %}>
    22{% for entry in summary %}
    33<strong>{{ entry.label }}</strong>{% if entry.value %}: <bdi>{{ entry.value }}</bdi>{% endif %}
    44{% endfor %}
    5 </div>
     5</span>
Version 1, edited 14 months ago by Mariusz Felisiak (previous) (next) (diff)

comment:6 by Tom Carrick, 14 months ago

Owner: changed from nobody to Tom Carrick
Status: newassigned

comment:7 by Mariusz Felisiak, 14 months ago

Has patch: set
Triage Stage: AcceptedReady for checkin

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 14 months ago

Resolution: fixed
Status: assignedclosed

In d687febc:

Fixed #34383 -- Fixed layout of admin fieldsets with multiple fields on the same line.

Thanks Antonio Candido Nazareth junior for the report.

Regression in 96a598356a9ea8c2c05b22cadc12e256a3b295fd.

Co-authored-by: Mariusz Felisiak <felisiak.mariusz@…>

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 14 months ago

Resolution: fixed
Status: assignedclosed

In 788f7b81:

[4.2.x] Fixed #34383 -- Fixed layout of admin fieldsets with multiple fields on the same line.

Thanks Antonio Candido Nazareth junior for the report.

Regression in 96a598356a9ea8c2c05b22cadc12e256a3b295fd.

Co-authored-by: Mariusz Felisiak <felisiak.mariusz@…>

Backport of d687febce5868545f99974d2499a91f81a32fef5 from main

comment:10 by GitHub <noreply@…>, 14 months ago

In b347dc6:

Refs #34383 -- Corrected margins in admin fieldsets with multiple fields on the same line on small screens.

Regression in d687febce5868545f99974d2499a91f81a32fef5.

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 14 months ago

In 47530bf:

[4.2.x] Refs #34383 -- Corrected margins in admin fieldsets with multiple fields on the same line on small screens.

Regression in d687febce5868545f99974d2499a91f81a32fef5.
Backport of b347dc63d5468564cbb7050461565f4f89032664 from main

Note: See TracTickets for help on using tickets.
Back to Top