9 Replies Latest reply: Nov 11, 2010 8:23 AM by istrasci RSS

    Flex 3 - List - checkbox itemrenderer enabled property

    istrasci

      I have a list that uses a checkbox itemrenderer.  The dataprovider is a collection of people.  When I load the data from a file, each list item shows the person's name (last, first -- labelFunction), and the checkbox's selected property shows the person's included property.  I.e.,

       

      Person
      Included?
      Smith, Dougx
      Williams, Bob
      Morris, Annex

       

       

      However, each person also has an active property.  I want to disable the checkbox for people who are inactive (meaning, "you can't include inactive people").  I have tried several methods to get this to work, including what's suggested here http://forums.adobe.com/thread/416786 to do the same thing in a datagrid.  However, none of them work and all the checkboxes are enabled regardless of the person's active status.  Here is my basic code:

       

      <mx:List id="peopleIncludedList"
           dataProvider="{someProvider}"
           labelFunction="peopleLabelFunction">
           <mx:itemRenderer>
                <mx:Component>
                     <mx:CheckBox change="onChange(event)"
                          selected="{outerDocument.isIncluded(data)}">
                          <mx:Script>
                               <![CDATA[
                                          
                                    private function onChange(e:Event):void
                                    {
                                         ...
                                    }
                               ]]>
                          </mx:Script>
                     </mx:CheckBox>
                </mx:Component>
           </mx:itemRenderer>
      </mx:List>
      

       

      Any help on this would be greatly appreciated.  Thank you.

       

        -- Ian

        • 1. Re: Flex 3 - List - checkbox itemrenderer enabled property
          Flex harUI Adobe Employee

          Try wrapping the Checkbox in something else so the checkbox itself can be

          disabled w/o disabling the entire renderer.

          • 2. Re: Flex 3 - List - checkbox itemrenderer enabled property
            Devtron Community Member

            Couldnt you do something like this? Just bind the "enabled" property?

             

                           <mx:CheckBox change="onChange(event)"
                                selected="{outerDocument.isIncluded(data)}"
                                enabled
            ="{data.IsThisPersonActiveField}"
                                >
                                <mx:Script>
                                     <![CDATA[
                                               
                                          private function onChange(e:Event):void
                                          {
                                               ...
                                          }
                                     ]]>
                                </mx:Script>
                           </mx:CheckBox>
            • 3. Re: Flex 3 - List - checkbox itemrenderer enabled property
              istrasci Community Member

              Yes, I was hoping it would be that easy, but that was one of the things I'd tried that inexplicably doesn't work.  Even if I do that, all the checkboxes are still enabled.

              • 4. Re: Flex 3 - List - checkbox itemrenderer enabled property
                Devtron Community Member

                It should work....

                 

                What is the value in that field? Maybe it needs to be translated to TRUE or FALSE, instead of whatever value is really in there?? What is the datatype for {data.IsThisGuyInactiveField} ?

                • 5. Re: Flex 3 - List - checkbox itemrenderer enabled property
                  istrasci Community Member

                  Yes, that property is actually Boolean.  I had also tried to bind to a different outerdocument method as I did for selected.  That method will even show the correct value, but it's like something is ignoring or overwriting that value at some point.

                   

                  One thing I've noticed is that certain methods like labelFunction callbacks run a lot; like way more times than the number of actual items in the dataprovider.  When I bound enabled to its own outerdocument method, I noticed it would run a lot as well.  My only guess right now is that it actually does get set to the correct value, but then the binding somehow updates, and rewrites everything as true.

                   

                  I'll explore the simple route a little more and see if I can't find anything concrete.

                  • 6. Re: Flex 3 - List - checkbox itemrenderer enabled property
                    Devtron Community Member

                    Usually when I see behaviour like that, yourlistcomponent.ValidateNow() works and fixes it.

                     

                    How is your dataprovider set? Is it done in ActionScript? If so, you could try to do the "ValidateNow" to force it to draw immediately. I dunno, I am going out on a limb here, lol.

                     

                    Also, can you debug into the dataprovider, to verify that "true" or "false" really exists for that field? My guess is that the underlying value is not there or different than what you expect. Try to debug the dataprovider to see if its truly "true or false"?

                    • 7. Re: Flex 3 - List - checkbox itemrenderer enabled property
                      istrasci Community Member

                      Even explicitly setting it to false doesn't disable them.

                       

                      <mx:CheckBox change="onChange(event)"
                           selected="{outerDocument.isIncluded(data)}"
                           enabled
                      ="false"
                           >
                           <mx:Script>
                                <![CDATA[
                                                         
                                     private function onChange(e:Event):void
                                     {
                                          ...
                                     }
                                ]]>
                           </mx:Script>
                      </mx:CheckBox
                      • 8. Re: Flex 3 - List - checkbox itemrenderer enabled property
                        Flex harUI Adobe Employee

                        I don't have time to check, but I recall that the renderers are set to

                        enabled=true during recycling.  That's why I'd try burying it one level

                        deeper.

                        • 9. Re: Flex 3 - List - checkbox itemrenderer enabled property
                          istrasci Community Member

                          Here's what I finally got to work.  I used an HBox as the itemrenderer and stuffed the checkbox in there, as well as a label (thus doing away with my old labelFunction).  Thanks harUI!

                           

                          <mx:itemRenderer>
                               <mx:Component>
                                    <mx:HBox width="100%">
                                         <mx:CheckBox change="onChange(event)"
                                              enabled="{data.active}"
                                              selected="{outerDocument.findInspectorInJoins(InspectorRef(data))}">
                                              <mx:Script>
                                                   <![CDATA[
                                                        private function onChange(e:Event):void
                                                        {
                                                             ...
                                                        }
                                                   ]]>
                                              </mx:Script>
                                         </mx:CheckBox>
                                         <mx:Label width="100%" text="{data.last + ', ' + data.first}"/>
                                    </mx:HBox>
                               </mx:Component>
                          </mx:itemRenderer>