Skip to content

Commit eef631a

Browse files
authored
fix: tabular inline stripes / delete link (#1190)
1 parent 9913a45 commit eef631a

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

src/unfold/static/admin/js/inlines.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,23 @@
9696
.removeClass(options.emptyCssClass)
9797
.addClass(options.formCssClass)
9898
.attr("id", options.prefix + "-" + nextIndex);
99+
99100
addInlineDeleteButton(row);
100101
row.find("*").each(function () {
101102
updateElementIndex(this, options.prefix, totalForms.val());
102103
});
104+
103105
// Insert the new form when it has been fully edited.
104-
row.insertBefore($(template));
106+
// !CHANGED from original
107+
if ($(template).parent().is("tbody")) {
108+
row
109+
.wrap('<tbody class="template"></tbody>')
110+
.parent()
111+
.insertBefore($(template).parent());
112+
} else {
113+
row.insertBefore($(template));
114+
}
115+
105116
// Update number of total forms.
106117
$(totalForms).val(parseInt(totalForms.val(), 10) + 1);
107118
nextIndex += 1;
@@ -183,7 +194,13 @@
183194
if (prevRow.length && prevRow.hasClass("row-form-errors")) {
184195
prevRow.remove();
185196
}
186-
row.remove();
197+
198+
// !CHANGED from original
199+
if (deleteButton.parent().parent().parent().parent().is("tbody")) {
200+
row.parent().remove();
201+
} else {
202+
row.remove();
203+
}
187204
nextIndex -= 1;
188205
// Pass the deleted form to the post-delete callback, if provided.
189206
if (options.removed) {
@@ -245,8 +262,11 @@
245262
}
246263

247264
// Create the delete buttons for all unsaved inlines:
265+
// !CHANGED from original, added parent() and used find() instead of filter()
248266
$this
249-
.filter(
267+
.parent()
268+
.parent()
269+
.find(
250270
"." +
251271
options.formCssClass +
252272
":not(.has_original):not(." +

src/unfold/static/unfold/css/styles.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/unfold/styles.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,13 @@ table tr.selected th {
264264
@apply hidden;
265265
}
266266

267+
.tabular-table tbody.has_original,
267268
.tabular-table .template tr {
268269
@apply border-t border-base-200 dark:border-base-800;
269270
}
270271

271272
.add-row {
272-
@apply align-middle bg-base-50 px-3 py-5 font-normal text-right dark:bg-white/[.02];
273+
@apply align-middle bg-white px-3 py-5 font-normal text-right dark:bg-base-900;
273274
}
274275

275276
[data-inline-type="stacked"] .add-row {

src/unfold/templates/admin/edit_inline/tabular.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ <h2 id="{{ inline_admin_formset.formset.prefix }}-heading" class="bg-base-100 bo
1818
{% if inline_admin_formset.is_collapsible %}</summary>{% endif %}
1919

2020
{{ inline_admin_formset.formset.non_form_errors }}
21-
2221
<div class="border border-base-200 mb-6 overflow-x-auto rounded shadow-sm dark:border-base-800" data-simplebar data-simplebar-auto-hide="false">
23-
<table class="tabular-table w-full" {% if inline_admin_formset.opts.ordering_field %}data-ordering-field="{{ inline_admin_formset.opts.ordering_field }}" x-on:end="sortRecords" x-sort.ghost{% endif %}>
22+
<table class="tabular-table w-full [&>tbody:nth-child(odd)]:bg-base-50 [&>tbody:nth-child(odd)]:dark:bg-white/[.02]" {% if inline_admin_formset.opts.ordering_field %}data-ordering-field="{{ inline_admin_formset.opts.ordering_field }}" x-on:end="sortRecords" x-sort.ghost{% endif %}>
2423
{% include "unfold/helpers/edit_inline/tabular_heading.html" %}
2524

2625
{% for inline_admin_form in inline_admin_formset %}

src/unfold/templates/unfold/helpers/edit_inline/tabular_field.html

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
{% if field.is_readonly %}
1313
{% include "unfold/helpers/field_readonly_value.html" with tabular=1 %}
1414
{% else %}
15-
{{ field.field }}
15+
<div class="flex flex-col">
16+
{{ field.field }}
1617

17-
{% if field.field.errors|length > 0 %}
18-
<div class="mt-1 text-red-600 text-sm dark:text-red-500">
19-
{% for error in field.field.errors %}
20-
{{ error }}
21-
{% endfor %}
22-
</div>
23-
{% endif %}
18+
{% if field.field.errors|length > 0 %}
19+
<div class="mt-1 text-red-600 text-sm dark:text-red-500">
20+
{% for error in field.field.errors %}
21+
{{ error }}
22+
{% endfor %}
23+
</div>
24+
{% endif %}
25+
</div>
2426
{% endif %}
2527
</div>

0 commit comments

Comments
 (0)