Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions django/contrib/admin/static/admin/css/forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ form .form-row p {
padding-left: 0;
}

.form-row > div {
.flex-container {
display: flex;
flex-wrap: wrap;
}

.form-multiline > div {
padding-bottom: 10px;
}

/* FORM LABELS */

label {
Expand Down Expand Up @@ -191,7 +195,6 @@ form .aligned table p {
}

fieldset .fieldBox {
float: left;
margin-right: 20px;
}

Expand Down
10 changes: 4 additions & 6 deletions django/contrib/admin/static/admin/css/responsive.css
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,6 @@ input[type="submit"], button {
display: none;
}

form .form-row p.datetime {
width: 100%;
}

.datetime input {
width: 50%;
max-width: 120px;
Expand Down Expand Up @@ -564,15 +560,17 @@ input[type="submit"], button {

.aligned .form-row,
.aligned .form-row > div {
display: flex;
flex-wrap: wrap;
max-width: 100vw;
}

.aligned .form-row > div {
width: calc(100vw - 30px);
}

.flex-container {
flex-flow: column;
}

textarea {
max-width: none;
}
Expand Down
1 change: 0 additions & 1 deletion django/contrib/admin/static/admin/css/rtl.css
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ form .wide input + div.help {
}

fieldset .fieldBox {
float: right;
margin-left: 20px;
margin-right: 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@

<div class="form-row">
{{ form.password1.errors }}
<div>{{ form.password1.label_tag }} {{ form.password1 }}</div>
<div class="flex-container">{{ form.password1.label_tag }} {{ form.password1 }}</div>
{% if form.password1.help_text %}
<div class="help"{% if form.password1.id_for_label %} id="{{ form.password1.id_for_label }}_helptext">{% endif %}{{ form.password1.help_text|safe }}</div>
{% endif %}
</div>

<div class="form-row">
{{ form.password2.errors }}
<div>{{ form.password2.label_tag }} {{ form.password2 }}</div>
<div class="flex-container">{{ form.password2.label_tag }} {{ form.password2 }}</div>
{% if form.password2.help_text %}
<div class="help"{% if form.password2.id_for_label %} id="{{ form.password2.id_for_label }}_helptext"{% endif %}>{{ form.password2.help_text|safe }}</div>
{% endif %}
Expand Down
35 changes: 19 additions & 16 deletions django/contrib/admin/templates/admin/includes/fieldset.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,30 @@
{% endif %}
{% for line in fieldset %}
<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 %}">
{% if line.fields|length == 1 %}{{ line.errors }}{% endif %}
{% if line.fields|length == 1 %}{{ line.errors }}{% else %}<div class="flex-container form-multiline">{% endif %}
{% for field in line %}
<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 %}>
<div>
{% if not line.fields|length == 1 and not field.is_readonly %}{{ field.errors }}{% endif %}
{% if field.is_checkbox %}
{{ field.field }}{{ field.label_tag }}
{% else %}
{{ field.label_tag }}
{% if field.is_readonly %}
<div class="readonly">{{ field.contents }}</div>
{% else %}
{{ field.field }}
{% endif %}
<div class="flex-container{% if not line.fields|length == 1 %} 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 %} checkbox-row{% endif %}">
{% if field.is_checkbox %}
{{ field.field }}{{ field.label_tag }}
{% else %}
{{ field.label_tag }}
{% if field.is_readonly %}
<div class="readonly">{{ field.contents }}</div>
{% else %}
{{ field.field }}
{% endif %}
{% 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>{{ field.field.help_text|safe }}</div>
</div>
{% 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>{{ field.field.help_text|safe }}</div>
</div>
{% endif %}
{% endfor %}
{% if not line.fields|length == 1 %}</div>{% endif %}
</div>
{% endfor %}
</fieldset>
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@

<div class="form-row">
{{ form.old_password.errors }}
<div>{{ form.old_password.label_tag }} {{ form.old_password }}</div>
<div class="flex-container">{{ form.old_password.label_tag }} {{ form.old_password }}</div>
</div>

<div class="form-row">
{{ form.new_password1.errors }}
<div>{{ form.new_password1.label_tag }} {{ form.new_password1 }}</div>
<div class="flex-container">{{ form.new_password1.label_tag }} {{ form.new_password1 }}</div>
{% if form.new_password1.help_text %}
<div class="help"{% if form.new_password1.id_for_label %} id="{{ form.new_password1.id_for_label }}_helptext"{% endif %}>{{ form.new_password1.help_text|safe }}</div>
{% endif %}
</div>

<div class="form-row">
{{ form.new_password2.errors }}
<div>{{ form.new_password2.label_tag }} {{ form.new_password2 }}</div>
<div class="flex-container">{{ form.new_password2.label_tag }} {{ form.new_password2 }}</div>
{% if form.new_password2.help_text %}
<div class="help"{% if form.new_password2.id_for_label %} id="{{ form.new_password2.id_for_label }}_helptext"{% endif %}>{{ form.new_password2.help_text|safe }}</div>
{% endif %}
Expand Down
12 changes: 6 additions & 6 deletions tests/admin_inlines/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,13 @@ def test_stacked_inline_hidden_field_with_view_only_permissions(self):
)
# The div containing the position field is hidden.
self.assertInHTML(
'<div class="fieldBox field-position hidden">'
'<div class="flex-container fieldBox field-position hidden">'
'<label class="inline">Position:</label>'
'<div class="readonly">0</div></div>',
response.rendered_content,
)
self.assertInHTML(
'<div class="fieldBox field-position hidden">'
'<div class="flex-container fieldBox field-position hidden">'
'<label class="inline">Position:</label>'
'<div class="readonly">1</div></div>',
response.rendered_content,
Expand All @@ -382,14 +382,14 @@ def test_stacked_inline_single_hidden_field_in_line_with_view_only_permissions(
# The whole line containing position field is hidden.
self.assertInHTML(
'<div class="form-row hidden field-position">'
"<div><label>Position:</label>"
'<div class="readonly">0</div></div></div>',
'<div><div class="flex-container"><label>Position:</label>'
'<div class="readonly">0</div></div></div></div>',
response.rendered_content,
)
self.assertInHTML(
'<div class="form-row hidden field-position">'
"<div><label>Position:</label>"
'<div class="readonly">1</div></div></div>',
'<div><div class="flex-container"><label>Position:</label>'
'<div class="readonly">1</div></div></div></div>',
response.rendered_content,
)

Expand Down
6 changes: 4 additions & 2 deletions tests/admin_views/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8105,11 +8105,13 @@ def test_mixin(self):
self.assert_field_visible(response, "second")

def assert_field_visible(self, response, field_name):
self.assertContains(response, '<div class="fieldBox field-%s">' % field_name)
self.assertContains(
response, f'<div class="flex-container fieldBox field-{field_name}">'
)

def assert_field_hidden(self, response, field_name):
self.assertContains(
response, '<div class="fieldBox field-%s hidden">' % field_name
response, f'<div class="flex-container fieldBox field-{field_name} hidden">'
)

def assert_fieldline_visible(self, response):
Expand Down