[3.2.x] Fixed #33083 -- Fixed selecting all items in the admin changelist when actions are both top and bottom.

Thanks Benjamin Locher for the report.

Regression in 30e59705fc.
Backport of b0ed619303 from main
This commit is contained in:
Carlton Gibson 2021-09-21 19:58:00 +02:00 committed by Mariusz Felisiak
parent e235c7815a
commit 6760f4fa25
4 changed files with 22 additions and 8 deletions

View File

@ -36,7 +36,10 @@
function clearAcross(options) {
reset(options);
document.querySelector(options.acrossInput).value = 0;
const acrossInputs = document.querySelectorAll(options.acrossInput);
acrossInputs.forEach(function(acrossInput) {
acrossInput.value = 0;
});
document.querySelector(options.actionContainer).classList.remove(options.selectedClass);
}
@ -107,8 +110,10 @@
document.querySelectorAll(options.acrossQuestions + " a").forEach(function(el) {
el.addEventListener('click', function(event) {
event.preventDefault();
const acrossInput = document.querySelector(options.acrossInput);
acrossInput.value = 1;
const acrossInputs = document.querySelectorAll(options.acrossInput);
acrossInputs.forEach(function(acrossInput) {
acrossInput.value = 1;
});
showClear(options);
});
});

View File

@ -11,3 +11,7 @@ Bugfixes
* Fixed a bug in Django 3.2 that caused incorrect links on read-only fields in
admin (:ticket:`33077`).
* Fixed a regression in Django 3.2 that caused incorrect selection of items
across all pages when actions were placed both on the top and bottom of the
admin change-list view (:ticket:`33083`).

View File

@ -133,6 +133,7 @@ class NoListDisplayLinksParentAdmin(admin.ModelAdmin):
list_display_links = None
list_display = ['name']
list_editable = ['name']
actions_on_bottom = True
site.register(Parent, NoListDisplayLinksParentAdmin)

View File

@ -1444,12 +1444,13 @@ class SeleniumTests(AdminSeleniumTestCase):
question = self.selenium.find_element_by_css_selector('.actions > .question')
clear = self.selenium.find_element_by_css_selector('.actions > .clear')
select_all = self.selenium.find_element_by_id('action-toggle')
select_across = self.selenium.find_element_by_name('select_across')
select_across = self.selenium.find_elements_by_name('select_across')
self.assertIs(question.is_displayed(), False)
self.assertIs(clear.is_displayed(), False)
self.assertIs(select_all.get_property('checked'), False)
self.assertEqual(select_across.get_property('value'), '0')
for hidden_input in select_across:
self.assertEqual(hidden_input.get_property('value'), '0')
self.assertIs(selection_indicator.is_displayed(), True)
self.assertEqual(selection_indicator.text, '0 of 100 selected')
self.assertIs(select_all_indicator.is_displayed(), False)
@ -1458,7 +1459,8 @@ class SeleniumTests(AdminSeleniumTestCase):
self.assertIs(question.is_displayed(), True)
self.assertIs(clear.is_displayed(), False)
self.assertIs(select_all.get_property('checked'), True)
self.assertEqual(select_across.get_property('value'), '0')
for hidden_input in select_across:
self.assertEqual(hidden_input.get_property('value'), '0')
self.assertIs(selection_indicator.is_displayed(), True)
self.assertEqual(selection_indicator.text, '100 of 100 selected')
self.assertIs(select_all_indicator.is_displayed(), False)
@ -1467,7 +1469,8 @@ class SeleniumTests(AdminSeleniumTestCase):
self.assertIs(question.is_displayed(), False)
self.assertIs(clear.is_displayed(), True)
self.assertIs(select_all.get_property('checked'), True)
self.assertEqual(select_across.get_property('value'), '1')
for hidden_input in select_across:
self.assertEqual(hidden_input.get_property('value'), '1')
self.assertIs(selection_indicator.is_displayed(), False)
self.assertIs(select_all_indicator.is_displayed(), True)
@ -1475,7 +1478,8 @@ class SeleniumTests(AdminSeleniumTestCase):
self.assertIs(question.is_displayed(), False)
self.assertIs(clear.is_displayed(), False)
self.assertIs(select_all.get_property('checked'), False)
self.assertEqual(select_across.get_property('value'), '0')
for hidden_input in select_across:
self.assertEqual(hidden_input.get_property('value'), '0')
self.assertIs(selection_indicator.is_displayed(), True)
self.assertEqual(selection_indicator.text, '0 of 100 selected')
self.assertIs(select_all_indicator.is_displayed(), False)