No, validation is not blocking.  It is just that the itemEditor is going
away.  What most folks do is check validation on ITEM_EDIT_END and
prevent the change to the dataprovider by calling preventDefault().  You
can also catch ITEM_EDIT_BEGINNING and return the editor to the bad cell
if the user is tabbing or clicking another cell, but if the user clicks
outside you can't really restore focus to the cell.

 

If you want to get really fancy then your itemRenderers will color
differently if they are invalid.

 

-Alex

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Lex
Sent: Tuesday, March 20, 2007 9:59 PM
To: [email protected]
Subject: [flexcoders] Can validation prevent text input entry?

 

Hi there,

 

    I have a TextInput type that I am using as an itemEditor in a
DataGrid.  I'm trying to prevent users from entering anything but
'dollar' amounts.  I have the class below, but it doesn't work as
expected...  I can edit the grid cell, enter a letter, and then exit the
grid without warning.  It's only when I click on the grid to edit it a
second time, that the red halo with the 'invalid input' flag appears.
Help appreciated.

 

 

<?xml version="1.0" encoding="utf-8"?>

<mx:TextInput

focusOut="validateData();" xmlns:mx="http://www.adobe.com/2006/mxml";
width="100%" height="100%" implements="mx.core.IFactory"> 

<mx:Script> 

<![CDATA[

import mx.events.ValidationResultEvent; 

import mx.controls.dataGridClasses.DataGridColumn; 

 

public var dataField:String; 

private var rowData:Object; 

 

[

Bindable]private var contentValue:String; 

 

 

public function newInstance():*{ 

return new GenericDollarFormatItemEditor(); 

}

 

private function validateData():void{ 

cv.validate();

}

 

override public function set data(value:Object):void { 

if( value != null ){ 

rowData = value; 

 

if( !(value is DataGridColumn) && dataField != null ){ 

contentValue = value[dataField];

this.text = value[dataField]; 

} 

}

}

 

]]>

</mx:Script> 

<mx:CurrencyValidator id="cv" source="{this}" listener="{this}"
property="text" alignSymbol="left" /> 

</mx:TextInput>

 

Reply via email to