Opened 104 minutes ago
#36757 new Cleanup/optimization
Optionally ignore change event in list view
| Reported by: | Jacob Rief | Owned by: | |
|---|---|---|---|
| Component: | contrib.admin | Version: | dev |
| Severity: | Normal | Keywords: | list-view, change-event |
| Cc: | Jacob Rief | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
I am the author of the popular 3rd party library https://github.com/jrief/django-admin-sortable2 used in approximately 1.5% of all Django installations. It is used to sort the entries in the list view of the Django-Admin. There however is a problem: Whenever one reorders entries and immediatly afterwards attemps to delete an entry, an alert message pops up, warning the user about unsaved changes.
Please check this issue https://github.com/jrief/django-admin-sortable2/issues/397 for details.
The easiest solution to fix this would be to just ignore that change. By applying this simple patch:
--- a/django/contrib/admin/static/admin/js/actions.js
+++ b/django/contrib/admin/static/admin/js/actions.js
@@ -151,7 +151,7 @@
updateCounter(actionCheckboxes, options);
lastChecked = target;
} else {
- list_editable_changed = true;
+ list_editable_changed = !target.classList.contains('ignore-list-changes');
}
});
});
this issue can be solved without causing any harm to other applications. I then would apply the CSS class ignore-list-changes to the <tbody> before dragging an entry and remove it afterwards. Btw., a few lines above, the CSS class action-select is used to prevent a similar use-case, so this patch follows the same logic.
This patch can also be used by other 3rd party libraries which change fields inside the list view and want to prevent such a warning message.
The class name ignore-list-changes is of course open for debate.
If this patch is accepted, I'll create a pull request.