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: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Alex Sent: Wednesday, March 21, 2007 7:52 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Can validation prevent text input entry? Anyone? --- In flexcoders@yahoogroups.com <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: flexcoders@yahoogroups.com <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: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> [mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> ] On Behalf Of Lex > Sent: Tuesday, March 20, 2007 9:59 PM > To: flexcoders@yahoogroups.com <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> >