Prpbpably when the focus goes to the alert, the validator fires again
since the datagrid lost focus and another alrt goes up which...

 

I do not recommend alerts and itemeditors

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Ramsey, Robert L
Sent: Monday, October 15, 2007 8:24 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] odd behavior when editing in a datagrid

 

Hi,

 

I'm just playing around and learning how to handle it when users edit a
datagrid.  I did a copy and paste from the Flex help:

 

<?xml version="1.0"?>

<!-- itemRenderers\events\EndEditEventFormatter.mxml -->

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";>

    

    <mx:Script>

        <![CDATA[

        

            import mx.controls.TextInput;

            import mx.events.DataGridEvent;

            import mx.events.DataGridEventReason;

            import mx.formatters.NumberFormatter;

            import mx.collections.ArrayCollection;

            import mx.controls.Alert;

        

            [Bindable]

            private var initDG:ArrayCollection = new ArrayCollection([

                {Artist:'Pavement', Album:'Slanted and Enchanted', 

                    Price:11.99},

                {Artist:'Pavement', Album:'Brighten the Corners', 

                    Price:11.99 }

            ]);

            

            private var myFormatter:NumberFormatter=new
NumberFormatter();

            

            public function formatData(event:DataGridEvent):void {


                // Check the reason for the event.

                if (event.reason == DataGridEventReason.CANCELLED)

                {

                    // Do not update cell.

                    return;

                }

 

                // Get the new data value from the editor.

                var newData:String= 

 
TextInput(event.currentTarget.itemEditorInstance).text;

 

                if(newData == "")

                {

                    // Prevent the user from removing focus, 

                    // and leave the cell editor open.

                    event.preventDefault();

                    // Write a message to the errorString property. 

                    // This message appears when the user 

                    // mouses over the editor.

                    TextInput(myGrid.itemEditorInstance).errorString=

                        "Enter a valid string.";

                }

            }           

                        

        ]]>

    </mx:Script>

    

    <mx:DataGrid id="myGrid" 

        dataProvider="{initDG}" 

        editable="true" 

        itemEditEnd="formatData(event);"> 

        <mx:columns>

            <mx:DataGridColumn dataField="Artist"/>

            <mx:DataGridColumn dataField="Album"/>

            <mx:DataGridColumn dataField="Price"/>

        </mx:columns>       

    </mx:DataGrid>  

</mx:Application>

 

 

 

The really thing that is bothering me though is that I added the
following Alert message just to see what the event.reason message was:

 

Alert.show(event.reason.toString());

 

But that locks up the app in IE 7.  Even if I just make it
Alert.show("hello"); the browser stops responding.  But if I use a label
instead of an alert, it works.  I just dropped a label on the form and
added the line mylabel.text=event. reason.toString());  That works just
fine and everything is smooth and I can see the reason just fine.

 

Anyone else experience this or know why one should lock up the app?  It
isn't a big deal since I won't be using this functionality in
production, I was just curious.

 

Thanks,

 

Bob

 

 

Reply via email to