Not yet rated

Problem

We want to validate user input in editable datagrid, and revert the original value(undo) if necessary.

Solution

Handle the ‘itemEditEnd’ Event dispatched by the datagrid.

Detailed explanation

User input is empty, we got the Event, prevent the default behavior, and revert the value form the modeling.

        
  
  
        /**
* validate user input, revert the original value if necessary.
*/
protected function datagirdTest_itemEditEndHandler(event:DataGridEvent):void {
if(event.dataField != "Name") { // chech the field;
return;
}
var input:String = (datagirdTest.itemEditorInstance as TextInput).text; // get the user input data.
if(input == null || input == "") {
event.preventDefault(); // prevent default behavior
// var filed:String = (datagirdTest.columns[event.columnIndex] as DataGridColumn).editorDataField;
// trace(datagirdTest.itemEditorInstance[filed]);
(datagirdTest.itemEditorInstance as TextInput).text = (event.itemRenderer.data as XML).Name;// Undo: revert the original data by the selected item.
Alert.show(errorMesg);
return;
}
}
 
  

Ref: 
Using cell editing events - http://livedocs.adobe.com/flex/3/html/help.html?content=celleditor_7.html

We want to validate user input in editable datagrid, and revert the original value(undo) if necessary.


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes