It might be possible to customize the itemEditor factory to return the
last item editor.

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Richard Rodseth
Sent: Thursday, November 29, 2007 4:06 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] itemEditEnd preventDefault



Ack. Sent that accidentally. Anyway, I am using the CANCELLED reason as
below. Sorry I sent the wrong code before.  

Desired behaviour: In all cases, when the last validation was INVALID
(as reflected in event.itemRenderer.data.valid) I want focus to remain
in the cell, and the validator's red border to remain. 

It's working rather well now. The one issue is that if I do a TAB
(reason="OTHER") with invalid data, the editor gets re-activated but
because I don't call preventDefault in that case, the invalid data gets
committed. That's fine if the user enters new valid data, but if the
user does an ESC to deactivate the editor, the invalid data is in the
cell. 

If I change the code below to do preventDefault() in the "reason=OTHER"
branch" I don't have that issue, but then the re-activated editor does
not have the current (invalid) value that I would like it to have. 

Thanks.


On Nov 29, 2007 3:56 PM, Richard Rodseth <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote:



        if (event.itemRenderer.data.valid || event.reason ==
DataGridEventReason.CANCELLED) {

           // omitted

        } else if (event.reason == DataGridEventReason.OTHER) {

        // Losing focus outside the data grid - take it back 

        myGrid.editedItemPosition = {columnIndex:event.columnIndex,
rowIndex:event.rowIndex}

        

        } else { // Losing focus to new column or row - prevent it

        event.preventDefault();

        }

        }


        In all cases, when the last validation was invalid, I would like
focus to stay in the cell, and the red border to remain.  


        On Nov 29, 2007 2:36 PM, Alex Harui < [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> > wrote:
        

                

                There's a CANCELLED reason for Esc.
                 
                I'm kinda lost right now.  What do you want to happen on
                 
                -tabbing to next column
                -enter going to next row
                -clicking on another cell in a different row
                -scrolling
                -clicking outside DG
                -esc cancelling edit
                 
                Which cases aren't working?
                
                 
________________________________

                
                From: flexcoders@yahoogroups.com
<mailto:flexcoders@yahoogroups.com>  [mailto:flexcoders@yahoogroups.com
<mailto:flexcoders@yahoogroups.com> ] On Behalf Of Richard Rodseth
                
                Sent: Thursday, November 29, 2007 12:58 PM
                To: flexcoders@yahoogroups.com
<mailto:flexcoders@yahoogroups.com> 
                Subject: Re: [flexcoders] itemEditEnd preventDefault
                
                

                The edge cases will get you. One issue (so far) with
this is that if you Tab with an invalid value (focus is lost and
regained), then follow up with an Esc, the committed value will be the
invalid one. I might be able to live with this. If I call preventDefault
in the OTHER case, I don't have that issue, but then the editor regains
focus but without the current (invalid) value. 
                
                

                On Nov 29, 2007 12:38 PM, Richard Rodseth
<[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > wrote:
                

                        Actually, it turns out I have to take the
DataGridEventReason into account. 


                        private function handleItemEditEnd(event :
DataGridEvent) : void {

                          if (event.itemRenderer.data.valid ||
event.reason == DataGridEventReason.OTHER) {

                            // do some stuff;

                          } else if (event.reason ==
DataGridEventReason.OTHER) {

                            // Losing focus outside the data grid - take
it back

                            myGrid.editedItemPosition =
{columnIndex:event.columnIndex, rowIndex:event.rowIndex}

                          } else {

                            // Losing focus to another row or column -
prevent it

                            event.preventDefault();

                          }

                        }


                        On Nov 29, 2007 11:58 AM, Richard Rodseth
<[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > wrote:
                        

                                Thanks, Alex. I don't know if there's a
bug, per se. 

                                As I mentioned in my first post, I only
had an issue when losing focus to something outside the grid. I may have
a workable solution which is hopefully not too ugly: 

                                - on itemEditEnd, call preventDefault,
and re-activate the editor using editedItemPosition
                                - in the editor, override setFocus and
call the validator

                                I haven't tested this with scrolling.

                                On Nov 29, 2007 11:15 AM, Alex Harui <
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > wrote:
                                

                                

                                Keep in mind that, if the user scrolls,
or clicks outside the DG, there is no way to prevent the edit session
from ending (at least not without a whole bunch of work).
                                 
                                I just took a look at the code.  When
tabbing from one cell to another, preventDefault() on itemEditEnd should
keep the editor alive.  If you put  together a small test case I can try
to see why it doesn't work.

________________________________

                                
                                From: flexcoders@yahoogroups.com
<mailto:flexcoders@yahoogroups.com>  [mailto:flexcoders@yahoogroups.com
<mailto:flexcoders@yahoogroups.com> ] On Behalf Of Richard Rodseth
                                
                                Sent: Thursday, November 29, 2007 10:52
AM
                                To: flexcoders@yahoogroups.com
<mailto:flexcoders@yahoogroups.com> 
                                Subject: Re: [flexcoders] itemEditEnd
preventDefault
                                
                                

                                And if I omit preventDefault, the
invalid value remains, but the red focus ring turns blue. I've also
established that setting editedItemPosition creates a new item editor
(as I would expect), so I can't store and access a "valid" flag in the
item editor component. 


                                Is there some other way to prevent an
invalid field from losing focus? Or to restart the edit with the invalid
value and have it re-validate?
                                
                                
                                On Nov 28, 2007 1:51 PM, Richard Rodseth
<[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > wrote:
                                

                                That keeps(restores) the focus, but also
restores the pre-edit value. 


                                On Nov 28, 2007 1:20 PM, Alex Harui <
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > wrote:
                                

                                

                                IIRC, the pattern is to call
preventDefault and then set editedItemPosition to the current position.

________________________________

                                From: flexcoders@yahoogroups.com
<mailto:flexcoders@yahoogroups.com>  [mailto:flexcoders@yahoogroups.com
<mailto:flexcoders@yahoogroups.com> ] On Behalf Of Richard Rodseth
                                Sent: Wednesday, November 28, 2007 12:20
PM
                                To: flexcoders@yahoogroups.com
<mailto:flexcoders@yahoogroups.com> 
                                Subject: [flexcoders] itemEditEnd
preventDefault
                                
                                

                                I have an item renderer/editor that does
as-you-type validation using standard Flex validators, and updates a
"valid" property in the data. I wish to prevent the edit from ending if
the data is valid. 


                                When tabbing, the following works in
column one, but not in column two (the last editable column):


                                private function handleItemEditEnd(event
: DataGridEvent) : void {

                                if (event.itemRenderer.data.valid) {

                                // do some stuff

                                } else {

                                event.preventDefault();

                                }

                                
                                

                                Any ideas? Also, does the renderer get
any access to this event? If I want to move "valid" from the data to the
renderer itself, I suppose I would have to cast event.itemRenderer above
to my renderer type, and call a method or access a property.

                                
                                

                                Thanks.

                                

                                

                                

                                



                                

                                

                                

                                




                

                

                

                



 

Reply via email to