I also tried adding this to the arrColl_collectionChange function:

                if(list.selectedIndex == -1)
                {
                        Alert.show("No items are selected!");
                }

But the only time it fires is when the app first loads, presumably
because the list isn't yet populated. If I uncheck all the checkboxes,
it doesn't show. The event in question is the change event of the
checkbox, so it seems to me this ought to work. No?

I did get it to work by modifying as follows:

                if(!tArr.length)
                {
                        Alert.show("No items are selected!");
                }


--- In [email protected], "stldvd" <stl...@...> wrote:
>
> Hi Alex,
> 
> I've been studying your code at 
>
http://blog.flexexamples.com/2008/01/27/using-a-checkbox-control-as-a-list-item-renderer-in-flex/
> 
> You use the filter method on the underlying array (source) for the
> arrayCollection datasource of the list. The signature of your
function is:
> 
> private function selectedOnly(item:ListItemValueObject, idx:uint,
> arr:Array):Boolean {
>       return item.isSelected;
> }
> 
> The filter method, according to the Flex docs, 'executes a test
> function on each item in the array and constructs a new array for all
> items that return true for the specified function.' That I understand,
> and I can see that you're being returned an array, tArr. But how are
> you able to call a function with that signature and know that all
> three parameters are going to be passed in? I tried adding a fourth
> parameter - , porky:String - and it broke. How does this method know
> that idx:uint is OK, but porky:String isn't?
> 
> 
> 
> --- In [email protected], Alex Harui <aharui@> wrote:
> >
> > You could use a derivative of the example on my blog and then just
> test if selectedIndex != -1
> > 
> > From: [email protected] [mailto:[email protected]]
> On Behalf Of stldvd
> > Sent: Tuesday, January 06, 2009 1:47 PM
> > To: [email protected]
> > Subject: [flexcoders] Validating Checkboxes in an item renderer
> > 
> > 
> > Hi All,
> > 
> > I've got a checkbox in an item renderer. I need to know that at least
> > one checkbox has been selected in order for the data to be considered
> > valid and the 'save' function to go through. But I'm not sure how to
> > iterate through the checkboxes, since in the code there's only one:
> > 
> > <mx:VBox>
> > <mx:List id="myList" dataProvider="{_dp}" >
> > <mx:itemRenderer>
> > <mx:Component>
> > <mx:HBox horizontalScrollPolicy="off">
> > <mx:CheckBox selected="false" />
> > <mx:Label text="Sample" textAlign="right" width="150" />
> > </mx:HBox>
> > </mx:Component>
> > </mx:itemRenderer>
> > </mx:List>
> > </mx:VBox>
> > 
> > Any help appreciated.
> > 
> > -- David
> >
>


Reply via email to