Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-6261

CheckGroupSelector default selection state incorrect when the list of Checks is empty

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 7.4.0
    • 7.6.0, 8.0.0-M3
    • wicket
    • Patch

    Description

      When using a CheckGroupSelector and your list of Check objects is empty, the default selection state for the select all checkbox is true, when it should be false. If there are no check boxes in the list, by extension none are 'checked'; therefore the select all check box should reflect this and not be checked by default.

      I believe the problem is in CheckSelector.updateSelectorState():

      updateSelectorState: function(selectorId, findCheckboxes) {
      	var checkboxes = findCheckboxes(),
      			allChecked = true;
      	
      	for (var i = 0; i < checkboxes.length; i++) {
      		if ((checkboxes[i].disabled === false) && (checkboxes[i].checked === false)) {
      			allChecked = false;
      			break;
      		}
      	}
      	var selector = document.getElementById(selectorId);
      	selector.checked = allChecked;
      }
      

      If findCheckboxes() returns null or an empty list, the loop never executes and the allChecked variable remains set to true. A simple empty/null check on the list to determine the original value of the allChecked variable should do the trick:

      	allChecked = checkboxes !== null && checkboxes.length > 0;
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            mgrigorov Martin Tzvetanov Grigorov
            bjones86 Brian Jones
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment