#104833Recycler shows wrong number of selected records
Description
In the recycler module, when you select all or just one item, the buttons for Recover and Delete show the wrong number of selected records.
In javascript the number is calculated from the elements inside the array `markedRecordsForMassAction`
The array is filled in the `handleCheckboxStateChanged`
If we look at the Developer console, we will notice CustomEvent is fired with type `“multiRecordSelection:checkbox:state:changed”` if we select a record
Depending on where we
a) correct: we click on a checkbox the event is fired once, 1 is added/substracted to/from the number in the buttons
b) wrong: we click on the record row, the click event is fired twice – 2 is added/substracted to/from the number in the buttons
I believe it has something to do with RegularEvents and the propagation of events in the markup from the table row down to the checkbox. I don’t think that can be fixed very easily.
But looking at the code that handles the checkbox change event:
vendor/typo3/cms-recycler/Resources/Public/JavaScript/recycler.js
this.handleCheckboxStateChanged = e => {
const t = $(e.target), a = t.parents("tr"), s = a.data("table") + ":" + a.data("uid");
if (t.prop("checked")) this.markedRecordsForMassAction.push(s); else {
const e = this.markedRecordsForMassAction.indexOf(s);
e > -1 && this.markedRecordsForMassAction.splice(e, 1)
}
this.markedRecordsForMassAction.length > 0 ? (this.elements.$massUndo.find("span.text").text(this.createMessage(TYPO3.lang["button.undoselected"], [this.markedRecordsForMassAction.length.toString(10)])), this.elements.$massDelete.find("span.text").text(this.createMessage(TYPO3.lang["button.deleteselected"], [this.markedRecordsForMassAction.length.toString(10)]))) : this.resetMassActionButtons()
}
we see, that it is checked if the clicked element is in the array if we uncheck a checkbox, so if the element should be removed from the array.
This explains, why the following scenario happens (also: How to reproduce this bug )
- Create a page with one content element.
- Delete that content element
- Switch to the recycler module
- Alternate between clicking the record row and unchecking the checkbox multiple time
- Observe the numbers in the Recover and Delete buttons rising
Possible solution:
It has to be checked if the selected element is already available in the `markedRecordsForMassAction` array:
const j = this.markedRecordsForMassAction.indexOf(s);
if (t.prop("checked")) {
j < 0 && this.markedRecordsForMassAction.push(s);
} else {
j > -1 && this.markedRecordsForMassAction.splice(j, 1)
}Reviews 3
Related issues 1
Files 1
History 59
-
Sébastien Delcroix commented <span data-processor="relativetime" data-value="2024-09-07T06:53:25+00:00" > 09/07/24, 06:53 </span>
-
Sébastien Delcroix changed Related to #104142 <span data-processor="relativetime" data-value="2024-09-07T17:49:30+00:00" > 09/07/24, 17:49 </span>
-
Garvin Hicking commented and changed status
NewAccepted <span data-processor="relativetime" data-value="2025-01-28T09:20:16+00:00" > 01/28/25, 09:20 </span>I can confirm the count is off in v12-v14.
Also the count of recovered records in the info popup reports a wrong number.
-
Gerrit Code Review pushed patch set 1 for main to change 88618 status
AcceptedUnder Review <span data-processor="relativetime" data-value="2025-03-17T15:23:52+00:00" > 03/17/25, 15:23 </span> -
Gerrit Code Review pushed patch set 2 for main to change 88618 <span data-processor="relativetime" data-value="2025-03-18T07:17:16+00:00" > 03/18/25, 07:17 </span>
-
Gerrit Code Review pushed patch set 1 for 13.4 to change 88634 <span data-processor="relativetime" data-value="2025-03-18T07:39:30+00:00" > 03/18/25, 07:39 </span>
-
Gerrit Code Review pushed patch set 1 for 12.4 to change 88635 <span data-processor="relativetime" data-value="2025-03-18T07:42:17+00:00" > 03/18/25, 07:42 </span>
-
Anonymous commented and changed status
Under ReviewResolved done0 %100 % <span data-processor="relativetime" data-value="2025-03-18T07:45:09+00:00" > 03/18/25, 07:45 </span>Applied in changeset commit:d5252ac0a0c70ca7140b2f04d49311255f7bddfc.
-
Benni Mack changed status
ResolvedClosed <span data-processor="relativetime" data-value="2025-12-02T14:33:28+00:00" > 12/02/25, 14:33 </span>
This commit added a dispatch to ‘change’ Event to multi-record-selection : https://github.com/TYPO3/typo3/blob/d9323c00a3f61cfc142b598a63205f433b50971b/Build/Sources/TypeScript/backend/multi-record-selection.ts#L86 just before dispatching the ‘multiRecordSelection:checkbox:state:changed’ CustomEvent.
But the ‘change’ event is registered by ‘registerDispatchCheckboxStateChangedEvent()’ and already dispatches the ‘multiRecordSelection:checkbox:state:changed’ CustomEvent :
Thus the ‘multiRecordSelection:checkbox:state:changed’ is dispatched twice, so the callback when clicking on a table row in the recycler module too.
Maybe the second dispatch of ‘multiRecordSelection:checkbox:state:changed’ is no more useful and we can just remove it.