Problem/Motivation
If all the checkboxes in the rows of a "tableselect" table are already checked on page load, the "Check all" checkbox should be checked, too.
Original report by @acbramley
I have a form with a table select form element that uses a custom table to fill in the default values. This means that all checkboxes could be ticked already on page load, but currently this is not conveyed in the select all checkbox. Instead, on page load the select all checkbox is unticked and to deselect all of them means clicking it twice (bad user experience). This would be fairly easy to add into tableselect.js. Currently the element is hardcoded to be:
<input type="checkbox" class="form-checkbox" />
in the jquery .prepend(). We could instead loop over the child checkboxes first and add the checked attribute on load.
Beta phase evaluation
| Issue category | Bug |
|---|---|
| Unfrozen changes | Unfrozen because it only changes how the tableselect javascript reacts when all checkboxes are already checked |
| Prioritized changes | The main goal of this issue is contrib DX. |
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | drupal-tableselect-1995058-15.patch | 551 bytes | acbramley |
| #10 | drupal-tableselect-1995058-10.patch | 550 bytes | traviscarden |
Comments
Comment #1
acbramley commentedManaged to do this very easily with existing code, just needed it to run on something other than a click event and after the checkboxes var was filled out.
Comment #2
traviscarden commentedThis problem exists in Drupal 8, too, so it should be fixed there, too. Here's a reroll of the patch, consistent with our coding standards for d8.
Comment #3
jhedstromPatch no longer applies.
Comment #4
traviscarden commentedThanks, @jhedstrom. Here's a reroll.
Comment #5
jhedstromI was going to manually test this, but realized I can't think of a place in core where all the checkboxes would be checked by default. The ones I'm aware of are operation-based (user admin, content admin, term admin, etc), meaning the checkbox state doesn't persist between visits to the page.
Thoughts on how to test?
Comment #6
traviscarden commentedWell, this is probably the weirdest possible way to do this, but the attached patch will cause all checkboxes to render checked off except those in a table header. Thus any listing you view will have all the items checked off, but the summary checkboxes won't be affected on the server side. The People page at admin/people is a good page to test with. If you apply this patch and view that page, you'll see all the users checked off, but the header checkbox won't be checked. If you then apply the real patch in #4 and revisit the page (making sure you've disabled JS aggregation or cleared cache), you should see all the users checked off and the header checkbox.
Comment #7
jhedstromI manually tested this using the patch in #7 and it works as expected. Even though this isn't directly used anywhere in core, it is a win for contrib that utilizes the tableselect functionality.
I've updated the summary with a beta-phase evaluation.
Comment #8
traviscarden commentedThanks, @jhedstrom!
Comment #9
alexpottBreaks our 80 character comment limit
Comment #10
traviscarden commentedD'oh! Thanks, @alexpott.
Comment #11
traviscarden commentedMoving back to RTBC now that the testbot approves, since it was just a comment line length change.
Comment #13
webchickThe issue summary calls this a feature, but I'd classify it as a small UX bug, and that's what the issue is classified as, as well (fixed that). Because it's a bug fix with no other disruption, it's allowed by https://www.drupal.org/contribute/core/beta-changes.
Committed and pushed to 8.0.x. Thanks!
Comment #14
wiifmOriginal bug was against Drupal 7, lets backport this patch. Patch at #1 needs at least a comment length change.
Comment #15
acbramley commentedRerolled patch with update to comment wording and line length.
Comment #16
vbouchetI tested it on the latest D7 by visiting the admin/content page, selecting all nodes using the "select all" checkbox and then refreshing the page. Before applying the patch all nodes was selected after the refresh but the "select all" checkbox remained unselected. After applying the patch, all nodes are selected and the "select all" checkbox is selected also.
I think this patch is ready to be integrated in D7.
Comment #19
vbouchetReset the status has last Simpletest failure was a false positive.
Comment #22
David_Rothstein commentedTestbot fluke.
Comment #23
David_Rothstein commentedCommitted to 7.x - thanks!