MCPcopy
hub / github.com/django/django / inlineDeleteHandler

Function inlineDeleteHandler

django/contrib/admin/static/admin/js/inlines.js:175–218  ·  view source on GitHub ↗
(e1)

Source from the content-addressed store, hash-verified

173 };
174
175 const inlineDeleteHandler = function (e1) {
176 e1.preventDefault();
177 const deleteButton = $(e1.target);
178 const row = deleteButton.closest("." + options.formCssClass);
179 const inlineGroup = row.closest(".inline-group");
180 // Remove the parent form containing this button,
181 // and also remove the relevant row with non-field errors:
182 const prevRow = row.prev();
183 if (prevRow.length && prevRow.hasClass("row-form-errors")) {
184 prevRow.remove();
185 }
186 row.remove();
187 nextIndex -= 1;
188 // Pass the deleted form to the post-delete callback, if provided.
189 if (options.removed) {
190 options.removed(row);
191 }
192 document.dispatchEvent(
193 new CustomEvent("formset:removed", {
194 detail: {
195 formsetName: options.prefix,
196 },
197 }),
198 );
199 // Update the TOTAL_FORMS form count.
200 const forms = $("." + options.formCssClass);
201 $("#id_" + options.prefix + "-TOTAL_FORMS").val(forms.length);
202 // Show add button again once below maximum number.
203 if (maxForms.val() === "" || maxForms.val() - forms.length > 0) {
204 addButton.parent().show();
205 }
206 // Hide the remove buttons if at min_num.
207 toggleDeleteButtonVisibility(inlineGroup);
208 // Also, update names and ids for all remaining form controls so
209 // they remain in sequence:
210 let i, formCount;
211 const updateElementCallback = function () {
212 updateElementIndex(this, options.prefix, i);
213 };
214 for (i = 0, formCount = forms.length; i < formCount; i++) {
215 updateElementIndex($(forms).get(i), options.prefix, i);
216 $(forms.get(i)).find("*").each(updateElementCallback);
217 }
218 };
219
220 const toggleDeleteButtonVisibility = function (inlineGroup) {
221 if (

Callers

nothing calls this directly

Calls 5

updateElementIndexFunction · 0.85
removeMethod · 0.45
getMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected