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

Reference: https://www.drupal.org/core/beta-changes
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.

Comments

acbramley’s picture

Status: Active » Needs review
StatusFileSize
new514 bytes

Managed 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.

traviscarden’s picture

Version: 7.x-dev » 8.x-dev
Issue summary: View changes
StatusFileSize
new569 bytes

This 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.

jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Patch no longer applies.

traviscarden’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new550 bytes

Thanks, @jhedstrom. Here's a reroll.

jhedstrom’s picture

I 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?

traviscarden’s picture

StatusFileSize
new755 bytes

Well, 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.

jhedstrom’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

I 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.

traviscarden’s picture

Issue tags: +Quick fix

Thanks, @jhedstrom!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +JavaScript
+++ b/core/misc/tableselect.js
@@ -60,6 +60,10 @@
+    // If all checkboxes are checked on page load, make sure the select-all one is
+    // checked too, otherwise keep unchecked.

Breaks our 80 character comment limit

traviscarden’s picture

Status: Needs work » Needs review
StatusFileSize
new550 bytes

D'oh! Thanks, @alexpott.

traviscarden’s picture

Status: Needs review » Reviewed & tested by the community

Moving back to RTBC now that the testbot approves, since it was just a comment line length change.

  • webchick committed 3770353 on 8.0.x
    Issue #1995058 by TravisCarden, acbramley, jhedstrom: Tableselect "...
webchick’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

The 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!

wiifm’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Fixed » Patch (to be ported)
Issue tags: +Novice

Original bug was against Drupal 7, lets backport this patch. Patch at #1 needs at least a comment length change.

acbramley’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new551 bytes

Rerolled patch with update to comment wording and line length.

vbouchet’s picture

Status: Needs review » Reviewed & tested by the community

I 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.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: drupal-tableselect-1995058-15.patch, failed testing.

Status: Needs work » Needs review
vbouchet’s picture

Status: Needs review » Reviewed & tested by the community

Reset the status has last Simpletest failure was a false positive.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: drupal-tableselect-1995058-15.patch, failed testing.

Status: Needs work » Needs review
David_Rothstein’s picture

Status: Needs review » Reviewed & tested by the community

Testbot fluke.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks!

  • David_Rothstein committed bcb8761 on
    Issue #1995058 by TravisCarden, acbramley, vbouchet: Tableselect "select...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.