How do I create an item editor in a flex list component so that it changes?
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 when they are done with their changes, because I have to edit multiple chunks of data in the editor and I would also like to validate the data before closing the editor. I just don't know what to do in the button click event to close the item editor and commit it to the data provider.
a source to share
I would use data binding and give Flex the job for you.
There is a myObject with a bindable property myList: IList. Bind the screen to this object.
When you start editing, copy this list.
In 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;
}
}
a source to share
To handle editing multiple fields in a List control, you need to catch the ItemEditEnd event and then manually modify the fields of interest.
See "Example: Using a Custom Item Editor with a List Control" here - http://livedocs.adobe.com/flex/3/html/help.html?content=celleditor_9.html#226555 .
Usually the List will handle dispatching this event for you when you focus from a cell. I'm not sure about its properties from my head, but you should be able to construct this event in your click handler and then just dispatch it yourself.
a source to share