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

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

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 7.4.0
    • Fix Version/s: 7.6.0, 8.0.0-M3
    • Component/s: wicket
    • Labels:
    • Flags:
      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

        1. WICKET-6261-fix.patch
          0.7 kB
          Brian Jones

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: