Summary
On a one-page View, “Select / deselect all results” checks every visible row but does not recalculate the Apply to selected items button state.
This happens on a one-page View using VBO's normal settings.
The failure occurs in this order:
- select an action;
- click Select / deselect all results.
The row checkboxes become checked, but Apply to selected items remains disabled.
No JavaScript exception is produced.
Tested versions
- Drupal 11.4.4
- Views Bulk Operations
4.4.x-dev - VBO commit
1840f0120f - PHP 8.4.20
- Chromium 138 through Selenium
Cause
When VBO's multipage selection widget is absent, the row checkbox change handler normally recalculates the button state:
checkboxes.on('change', function () {
selectionObject.toggleButtonsState();
});
The all-results handler changes each row checkbox by assigning its checked property directly:
this.checked = value;
Changing a JavaScript property directly does not fire the checkbox change handler. The rows become checked, but the Apply button is not recalculated.
The problem is less visible when the click order is reversed. If rows are selected first and the action is chosen afterward, changing the action recalculates the button state. Users should not have to know or follow that special order.
Reproduction
This reproduction uses one VBO field with its default settings.
- Install Drupal 11.4.x.
- Ensure that a Basic page content type exists.
- On a clean Drupal 11.4 installation, apply the core Basic page recipe with
drush recipe core/recipes/page_content_type -y, or create an equivalent content type through the UI.
- On a clean Drupal 11.4 installation, apply the core Basic page recipe with
- Install and enable Views Bulk Operations
4.4.x-dev. - Create at least 10 published Basic page nodes.
- Go to Structure → Views → Add view.
- Create a View with these settings:
- View name:
VBO Apply button reproduction - Show:
Content - enable Create a page;
- Page title:
VBO Apply button reproduction - Path:
vbo-apply-button-reproduction - Display format:
Unformatted list - of:
fields - Items to display:
100 - Use a pager: checked
- View name:
- Click Save and edit.
- Under Fields, click Add.
- Search for
Views bulk operations, select Views bulk operations, then click Add and configure fields. - In the VBO field configuration dialog:
- make sure Exclude from display is not checked;
- leave Show an “Items selected” details element set to Default;
- leave Show a “Select / Deselect all results (all pages)” checkbox set to Default;
- expand Selected actions;
- check Publish content item;
- click Apply.
- Click Save for the View.
- Open
/vbo-apply-button-reproduction. - Confirm that the page shows the Select / deselect all results checkbox but does not show an Items selected details element.
- Select Publish content from the action dropdown.
- Confirm that Apply to selected items is disabled because no rows are selected.
- Click Select / deselect all results.
Actual result before the patch
- The select-all checkbox becomes checked.
- Every visible row checkbox becomes checked.
- Apply to selected items remains disabled.
- No JavaScript exception is logged.
Expected result
- Every visible row checkbox is checked.
- Apply to selected items is enabled because an action and rows are selected.
Proposed fix
Recalculate the button state after the all-results handler changes the visible row checkboxes:
$vboForm.find(/* row checkbox selector */).each(function () {
if (this.checked !== value) {
this.checked = value;
}
});
+ vboSelection.toggleButtonsState();
The multipage AJAX callback still performs its normal button-state recalculation after the server returns the selected count.
Regression test
The patch adds a FunctionalJavascript test to VBO's existing ViewsBulkOperationsBulkFormTest class.
The test:
- uses the existing VBO test field and leaves both visibility settings at their defaults;
- changes the View to an unformatted list;
- increases the pager size so every result fits on one page;
- confirms that the select-all checkbox is rendered and the Items selected details element is not;
- selects an action and confirms that Apply is disabled;
- clicks the real
.vbo-select-allcontrol; - confirms that every visible row is checked;
- asserts that Apply is enabled.
Before the fix, the final assertion fails:
The Apply button should be enabled when an action and rows are selected.
Failed asserting that true is false.
With the button-state patch applied, the focused test passes:
Tests: 1, Assertions: 44
AI disclosure
AI was used in preparing this contribution. I used ChatGPT interactively to help inspect the VBO code, investigate the failure, draft and revise the regression test and patch, run local commands and tests through a user-controlled shell tool, and refine the issue description.
I directed the investigation, manually reproduced the problem before the patch, reviewed and corrected the generated analysis, code, tests, and wording, and manually confirmed the corrected behaviour after applying the patch. I take responsibility for the issue report and the proposed changes.
Issue fork views_bulk_operations-3612755
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
thursday_bw commentedComment #4
thursday_bw commentedCreated merge request !163 with the fix and FunctionalJavascript regression test.
Verified locally:
- the focused test fails before the fix;
- the focused test passes after the fix with 1 test and 44 assertions;
- JavaScript syntax, PHP syntax, coding standards, and git diff checks pass.
The GitLab pipeline also passes.
Comment #5
graber commentedTests need updating, left a comment on the MR.
Comment #6
thursday_bw commentedHey @graber,
I changed the visibility of testSelectAllResultsEnablesApplyOnOnePage() to private and now call it from testViewsBulkOperationsAjaxUi().
That should resolve the testing performance issue.
Comment #7
graber commentedNeeds rebase.
Comment #8
thursday_bw commentedI missed that, sorry. Rebase complete. Thanks.
Comment #9
gaddman commentedThanks, this fixes the issue for me (Drupal 11.4.6, VBO 4.4.7. Code looks good, marking as reviewed.
Comment #10
thursday_bw commentedThanks @gaddman, genuinely glad to hear this fixed it for someone else.
At a previous job I somehow earned the nickname "the bug finder". If there's an obscure sequence of events that exposes something broken, apparently I have a knack for stumbling into it. 😄
Bug reports and patches can sometimes disappear into the void, so hearing that something I found and fixed has actually helped another person is really nice. Thanks for taking the time to test it and report back.
Comment #12
graber commentedThanks, optimized that test coverage a bit, remember that tests are not free (at least not for DA), especially the functionalJS ones.