3 Replies Latest reply on Sep 24, 2008 4:35 PM by ariadne137

    Dynamic repeating checkboxes - select all/deselect all

    ariadne137
      I have dynamic checkboxes in a Repeater.

      I want to create a button for Select All and Clear All that will select each checkbox and clear each checkbox respectively. I'm hitting a wall.

      Here's the checkbox code:
      <mx:Button id="subCatButtonSelect" label="Select All" click="selectAll();" />
      <mx:Repeater id="subCategoryPickerList">
      <mx:CheckBox id="subCategoryCheckbox" data="{subCategoryPickerList.currentItem.subCategoryID}" label="{subCategoryPickerList.currentItem.name}" width="175" />
      </mx:Repeater>

      Here's what I have for Select All, which is currently not working:

      private function selectAll():void {
      var idx:int;
      var len:int = subCategory.length;
      for (idx=0; idx<len; idx++) {
      subCategoryCheckbox[idx].selected = true;
      }
      }

      "subCategory" is an ArrayCollection supplying the data for each checkbox.

      All help is appreciated! Thanks so much!
        • 1. Re: Dynamic repeating checkboxes - select all/deselect all
          ntsiii Level 3
          Is your repeater working? You have not assigned a dataProvider to it in the tag, are you assigning it somewhere else? I assume it is a var named "subCategory"?

          What is not working?

          Your selection loop looks ok. Have you debugged it to make sure this:
          subCategoryCheckbox[idx]
          is returning a good reference? It should.

          You could test using a hard coded reference and run it from a button:
          subCategoryCheckbox[0].selected = true;

          Tracy
          • 2. Re: Dynamic repeating checkboxes - select all/deselect all
            ariadne137 Level 1
            Hi Tracy,

            Thanks for replying ...

            I actually got this working yesterday. I'm not quite sure how or why it suddenly started working, but I did the test you suggested (subCategoryCheckbox[0].selected = true; using a button) and debugged/tested every individual line of the function, and it resolved itself. (Yes, the dataProvider for the repeater is assigned somewhere else -- good question though).

            Thanks again for your help!
            • 3. Re: Dynamic repeating checkboxes - select all/deselect all
              ariadne137 Level 1
              Hi Tracy,

              Thanks for replying ...

              I actually got this working yesterday. I'm not quite sure how or why it suddenly started working, but I did the test you suggested (subCategoryCheckbox[0].selected = true; using a button) and debugged/tested every individual line of the function, and it resolved itself. (Yes, the dataProvider for the repeater is assigned somewhere else -- good question though).

              Thanks again for your help!