I managed a workaround with the following itemEditor (that is accepting e4x 
data):

<?xml version="1.0" encoding="utf-8"?>
<mx:TextInput xmlns:mx="http://www.adobe.com/2006/mxml"; 
implements="mx.core.IFactory"
updateComplete="dataChanged()" change="dataChanged()">
<mx:Script>
<![CDATA[
import mx.events.DataGridEvent;
import mx.validators.ValidationResult;
import mx.controls.dataGridClasses.DataGridColumn;
import flash.events.EventDispatcher;

public var dataField:String;


[Bindable]private var contentValue:String;

private function dataChanged():void{
contentValue = this.text;
super.data[dataField] = this.text;
}

public function newInstance():*{
return new GenericDollarFormatItemEditor();
}

override public function set data(value:Object):void {
if( value != null ){
super.data = value; 

if( !(value is DataGridColumn) && dataField != null ){ 
contentValue = value[dataField];
this.text = value[dataField];
} 
}
}

]]>
</mx:Script>
<mx:CurrencyValidator id="cv" source="{this}" property="text" 
alignSymbol="left" trigger="{this}" triggerEvent="change" required="true"/> 
</mx:TextInput>









  ----- Original Message ----- 
  From: Alex Harui 
  To: [email protected] 
  Sent: Thursday, March 22, 2007 1:55 AM
  Subject: RE: [flexcoders] Re: Can validation prevent text input entry?



  You could call a dataIsValid method on each itemEditorInstance.  Just know 
that the editor gets destroyed later and isn't around forever.




------------------------------------------------------------------------------

  From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Lex
  Sent: Wednesday, March 21, 2007 7:47 PM
  To: [email protected]
  Subject: Re: [flexcoders] Re: Can validation prevent text input entry?



  Thanks for the message Alex, however, is there no way to have the itemEditor 
handle this innately?  It'd be a cleaner solution than a huge itemEditEnd block 
inside of the datagrid container's mxml that needs to handle the various types 
of editors that the grid will contain.













    ----- Original Message ----- 

    From: Alex Harui 

    To: [email protected] 

    Sent: Wednesday, March 21, 2007 2:09 PM

    Subject: RE: [flexcoders] Re: Can validation prevent text input entry?



    ITEM_EDIT_END is dispatched from DataGrid

    <mx:DataGrid id="dg" itemEditEnd="itemEditEndHandler(event)" />

    private function itemEditEndHandler(event):void

    {

          if (!dataIsValid(dg.itemEditorInstance.text))

                event.preventDefault();

    }


----------------------------------------------------------------------------

    From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Alex
    Sent: Wednesday, March 21, 2007 7:52 AM
    To: [email protected]
    Subject: [flexcoders] Re: Can validation prevent text input entry?

    Anyone?

    --- In [email protected], "Lex" <[EMAIL PROTECTED]> wrote:
    >
    > Thanks for the response! Precisely how does one "listen for
    ITEM_EDIT_END"? (extremely new to flex)
    > 
    > If I do 
    > <mx:TextInput textInput="validateData(event)"
    > 
    > with a
    > 
    > 
    > 
    > private function validateData( event:TextEvent ):void{
    > 
    > 
    > 
    > }
    > 
    > 
    > where my validator has ID cv, how do I trigger validation, and then
    check the result, to finally call event.preventDefault() if the shit
    hits the fan?
    > 
    > 
    > Thanks for your help. The docs in this dept are incredibly lacking..
    > 
    > Alex
    > 
    > 
    > 
    > 
    > ----- Original Message ----- 
    > From: Alex Harui 
    > To: [email protected] 
    > Sent: Wednesday, March 21, 2007 1:12 AM
    > Subject: RE: [flexcoders] Can validation prevent text input entry?
    > 
    > 
    > 
    > 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