We want to validate user input in editable datagrid, and revert the original value(undo) if necessary.
Handle the ‘itemEditEnd’ Event dispatched by the datagrid.
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
+