Missing feature in actions.js (Django 3.2 and later)

116 views
Skip to first unread message

akiyoko

unread,
Feb 3, 2022, 9:04:25 AM2/3/22
to Django developers (Contributions to Django itself)
Hi everyone,

On the admin site, I've found a feature that existed in Django 2.2 but was lost with the update to Django 3.2.

In Django 2.2, if you clicked the "No, take me back" button on the delete confirmation page, the background color of the checked rows would remain highlighted and the action-counter display would remain counted up on the change list page. However, in Django 3.2, the background color of the selected row is not highlighted and the action-counter display is "0 of X selected".

Based on my investigation, I'm guessing that the problem is caused by the following fix to the JavaScript on the admin site that accompanies the update to Django 3.2.
https://github.com/django/django/commit/30e59705fc3e3e9e8370b965af794ad6173bf92b

The direct cause is that the following process in django/contrib/admin/static/admin/js/actions.js was removed in that fix.

~~~
        // Show counter by default
        $(options.counterContainer).show();
        // Check state of checkboxes and reinit state if needed
        $(this).filter(":checked").each(function(i) {
            $(this).parent().parent().toggleClass(options.selectedClass);
            updateCounter();
            if ($(options.acrossInput).val() === 1) {
                showClear();
            }
        });
~~~

In addition, it seems that the "checked" property of all elements in the "actionsEls" is now always false due to the change in the way the DOM load completion event is fired. We may need to take that into account when fixing.

Thanks in advance,


Akihito Yokose
change_list_page.png

Adam Johnson

unread,
Feb 3, 2022, 5:46:56 PM2/3/22
to Django developers (Contributions to Django itself)
Hi Akihito

Looking at the PR ( https://github.com/django/django/pull/12820 ) and ticket for that commit, it looks like purely an oversight that this feature was removed. Since you've done much of the research already, would you be able to make a PR? It should be possible to rewrite those lines of code in vanilla JS.

Adam

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/dacf2948-66b1-4e64-a30e-84e418bd0d8bn%40googlegroups.com.

akiyoko

unread,
Feb 4, 2022, 12:18:12 AM2/4/22
to Django developers (Contributions to Django itself)
Thanks, Adam.
I have created a ticket and a PR.

Ticket
https://code.djangoproject.com/ticket/33491
PR
https://github.com/django/django/pull/15395

However, since the JS code I wrote is a bit hachy, any other ideas?

Akihito Yokose
2022年2月4日金曜日 7:46:56 UTC+9 Adam Johnson:
Reply all
Reply to author
Forward
0 new messages