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 <mailto:[EMAIL PROTECTED]>  

        To: [email protected]
<mailto:[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]>  [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]
<mailto:flexcoders%40yahoogroups.com> , "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]
<mailto:flexcoders%40yahoogroups.com>  
        > 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:flexcoders%40yahoogroups.com> 
        [mailto:[email protected]
<mailto:flexcoders%40yahoogroups.com> ] On Behalf Of Lex
        > Sent: Tuesday, March 20, 2007 9:59 PM
        > To: [email protected]
<mailto:flexcoders%40yahoogroups.com> 
        > 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
<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