The UI selection logic doesn't work correctly

Created on 15 February 2023, almost 2 years ago
Updated 9 February 2024, 9 months ago

Problem/Motivation

Currently the logic doesn't cover correctly selected items.
We have two cases, when we use or force "Selection info" widget and when we don't use it rely on checked checkboxes in the view.
Currently it is possible to "Select all items" and then uncheck some checkboxes in the list and as result "0" entities will be selected, but buttons still will be active. So, it is possible to submit the form.
As a result we can face unexpected results like:

arning: Undefined array key "bulk_form_keys" in Drupal\views_bulk_operations\Plugin\views\field\ViewsBulkOperationsBulkForm->viewsFormSubmit() (line 917 of modules/contrib/views_bulk_operations/src/Plugin/views/field/ViewsBulkOperationsBulkForm.php)

or

DivisionByZeroError: Division by zero in Drupal\views_bulk_operations\ViewsBulkOperationsBatch::getList() (line 51 of /home/lob/www/drupal/web/modules/contrib/views_bulk_operations/src/ViewsBulkOperationsBatch.php)

and sometimes some other warnings.

Steps to reproduce

1) Create a view with bulk operations
2) Check "Always show selection info"
3) The view should return result for one page, for example only one result
4) Open your view
4) Click "Select / deselect all results (all pages, 1 total)", you should see that some entities are selected, for example "Selected 1 item"
5) Uncheck checkboxes in the table
6) You should see now "Selected 0 items"
7) "Apply to selected items" button is active, but it shouldn't, because no entities selected
8) Submit form and you should see warning or error

Another use-case:

1) Create a view with bulk operations that has at least 3 results
2) Open your view
3) Click the first item, you should see that one entity is selected, for example "Selected 1 item"
4) Then, shift+click the last item
5) It should now have all the items selected and list the correct count, but it doesn't. Instead, it says only 2 items are selected.

Proposed resolution

Handle differently selection for "Selection info" widget and without it

1) For selection info we rely on the results returned by ajax call

2) Without selection info, we rely on the previous logic, when count checked checkboxes.

๐Ÿ› Bug report
Status

Closed: duplicate

Version

4.2

Component

User interface

Created by

๐Ÿ‡ง๐Ÿ‡ชBelgium lobsterr

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024