Skip to content
Closed
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
10 changes: 9 additions & 1 deletion src/unfold/static/admin/js/inlines.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
const addInlineClickHandler = function (e) {
e.preventDefault();
const template = $("#" + options.prefix + "-empty");
// Check if template exists (has_add_permission check)
if (template.length === 0) {
return;
}
const row = template.clone(true);
row
.removeClass(options.emptyCssClass)
Expand Down Expand Up @@ -284,8 +288,12 @@

// Show the add button if allowed to add more items.
// Note that max_num = None translates to a blank string.
// Check if template exists (has_add_permission check)
const template = $("#" + options.prefix + "-empty");
const hasAddPermission = template.length > 0;
const showAddButton =
maxForms.val() === "" || maxForms.val() - totalForms.val() > 0;
hasAddPermission &&
(maxForms.val() === "" || maxForms.val() - totalForms.val() > 0);
if ($this.length && showAddButton) {
addButton.parent().show();
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tr class="form-row {% if inline_admin_form.original or inline_admin_form.show_url %}has_original{% endif %}{% if forloop.last and inline_admin_formset.has_add_permission %} empty-form{% endif %}" id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
<tr class="form-row {% if inline_admin_form.original or inline_admin_form.show_url %}has_original{% endif %}{% if forloop.last and inline_admin_formset.has_add_permission %} empty-form{% endif %}" id="{{ inline_admin_formset.formset.prefix }}-{% if forloop.last and inline_admin_formset.has_add_permission %}empty{% else %}{{ forloop.counter0 }}{% endif %}">
{% spaceless %}
{% for fieldset in inline_admin_form %}
{% for line in fieldset %}
Expand Down