Use EmailValidator to validate email cell editor
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="white">
<mx:Script>
import mx.collections.ArrayCollection;
import mx.events.DataGridEvent;
import mx.validators.EmailValidator;
import mx.controls.TextInput;
[Bindable]
public var myAC:ArrayCollection = new ArrayCollection([
{name:"a", email:"a@i.com"},
{name:"b", email:"b@i.com"}]);
private function onEditEnd(event:DataGridEvent):void
{
if(event.dataField == 'email'){
var fCell:Array=[event.columnIndex,event.rowIndex];
var newData:String = TextInput(event.currentTarget.itemEditorInstance).text;
var emailVal:EmailValidator = new EmailValidator();
var valResult:* = emailVal.validate(newData);
if(valResult.type == "invalid"){
trace("not valid");
}
}
}
</mx:Script>
<mx:DataGrid id="dg" width="350" height="150" dataProvider="{myAC}" itemEditEnd="onEditEnd(event)" editable="true">
<mx:columns>
<mx:DataGridColumn headerText="Name" dataField="name" />
<mx:DataGridColumn headerText="EMail" dataField="email" />
</mx:columns>
</mx:DataGrid>
</mx:Application>
Related examples in the same category