7 Replies Latest reply on Apr 21, 2010 9:51 AM by JockMahon

    override keyDownHandler

    JockMahon Level 1

      I have overridden both keyDownHandler and keyUpHandler to be empty functions that don't call their super methods.

      I have a datagrid that is editable

       

      When focus is in the editable textInput of the DG the edit renderer is removed when esc is pressed , where is this key been listened for . Is it in the item renderer

       

      thanks

        • 1. Re: override keyDownHandler
          Flex harUI Adobe Employee

          Yes, we are listening for keystrokes off of the editor

          1 person found this helpful
          • 2. Re: override keyDownHandler
            JockMahon Level 1

            whats the best thing to do, should i apply a custom item renderer instead of using the default one, that doesn't include a key listener

            • 3. Re: override keyDownHandler
              Flex harUI Adobe Employee

              I would use a capture phase listener and stop propagation of the event if

              the target is the itemEditorInstance and keyCode==Keyboard.ESCAPE

              1 person found this helpful
              • 4. Re: override keyDownHandler
                JockMahon Level 1

                kewl, how do i set up  a capture phase listener?

                • 5. Re: override keyDownHandler
                  Flex harUI Adobe Employee

                  In AS, it is the 3rd parameter to addEventListener.

                  • 6. Re: override keyDownHandler
                    JockMahon Level 1

                    i have added the key listener by implementing the IFocusManagerComponent

                    and as such don't use the addEventListener

                    • 7. Re: override keyDownHandler
                      JockMahon Level 1

                      just got back to this , thanks ur solution worked great, it ended up lookin like the following, to get rid of the item editor is had to create the datagrid event not sure if it's the best way to do it

                       

                       

                                  protected function onSearchGridCreation(event:FlexEvent):void
                                  {
                                      searchResultsDataGrid.addEventListener(KeyboardEvent.KEY_DOWN,gridKeyListener,true);
                                  }
                                 
                                  private function gridKeyListener(event:KeyboardEvent):void
                                  {
                                      if(( DataGrid(event.currentTarget).itemEditorInstance != null ) && ( event.keyCode == 27 ))
                                      {
                                          event.stopPropagation();   
                                         
                                          var dataGridEvent:DataGridEvent = new DataGridEvent(DataGridEvent.ITEM_EDIT_END, false, true);
                                         
                                          dataGridEvent.columnIndex  = searchResultsDataGrid.editedItemPosition.columnIndex
                                          dataGridEvent.dataField    = searchResultsDataGrid.columns[searchResultsDataGrid.editedItemPosition.columnIndex].dataF ield
                                          dataGridEvent.rowIndex     = searchResultsDataGrid.editedItemPosition.columnIndex
                                          dataGridEvent.itemRenderer = searchResultsDataGrid.editedItemRenderer
                                          dataGridEvent.reason       = "Dummy Reason";
                                          searchResultsDataGrid.dispatchEvent(dataGridEvent);
                                      }
                                  }