views:

1274

answers:

3

I have a list component and I have an item editor for the items in the list. I would like to have a button that the user clicks once they are done with their changes because I am having them edit multiple pieces of data in the editor and I would also like to validate the data before closing the editor as well. I just don't know what to do on the button's click event to make the item editor close and commit it's changes to the data provider.

A: 

You'll want to use a validator to validate the data, and I think maybe do something with the updateComplete and change events to delay the updating of the list component:

http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=celleditor_073_17.html

quoo
A: 

I would use data binding and let Flex do the work for you.

Have an object myObject with a bindable property myList:IList. Bind the display to this object.

When you start editing, copy that list.

On MouseEvent.CLICK:

var ed:Editor // Your list editing object.
var edProvider:IList = ed.dataProvider;
var targList:IList   = myObject.myList; 

var bool:Boolean     = ( myObject.myList.length > edProvider.length );
var len:int          = ( bool )? targList.length: edProvider.length; 

var item:*           = null;

for( var i:int = 0; i < len; i++ )
{
    try // a "just in case".  You probably will never have a problem.
    {
        item = edProvider.getItemAt( i );
        targList.setItemAt( item, i );
    }
    catch( error:Error )
    {
        continue;
    }
}
Christopher W. Allen-Poole
A: 

To handle the editing of multiple fields in a List control, you will need to catch the ItemEditEnd event and then manually change the fields you are interested in.

See "Example: Using a custom item editor with a List control" in here - http://livedocs.adobe.com/flex/3/html/help.html?content=celleditor_9.html#226555.

Usually the List will handle the dispatching of this event for you when you focus out of a cell. I'm not sure of its properties off the top of my head, but you should be able to construct this event in your button click handler, and then just dispatch it yourself.

merlinc
Thanks for the answer but, it's not quite what I'm looking for. The setting the value parts if fine it's just the validating and closing the item editor part I need help with.
smartdirt