tags:

views:

29

answers:

1

I have a text widget where I want to make enter event to behave like a tab event. so I capture the Key press event and raise a tab native event.

However the tab behavior is not reflected in the application. The code for event handler is

   public void onKeyPress(KeyPressEvent event) { 
            int keyCode = event.getNativeEvent().getKeyCode(); 
            if (keyCode == KeyCodes.KEY_ENTER) { 
               NativeEvent nativeEvent = 
               Document.get().
                 createKeyPressEvent(false,false,false,false,KeyCodes.KEY_TAB ); 
               DomEvent.fireNativeEvent(nativeEvent, this, this.getElement()); 
            } 

When I use the deprecated createKeyPressEvent with more argument, it fires the tab event but the behavior is not as per the tab key press, which is to move to next widget. The new code changes from the above code in createKeyPress event line as follows

     NativeEvent nativeEvent = 
       Document.get().
         createKeyPressEvent(false,false,false,false,
                      KeyCodes.KEY_TAB ,KeyCodes.KEY_TAB);
+1  A: 

Note that manually firing an event does not generate the default action associated with that event. For example, manually firing a focus event does not cause the element to receive focus (you must use its focus method for that), manually firing a submit event does not submit a form (use the submit method), manually firing a key event does not cause that letter to appear in a focused text input, and manually firing a click event on a link does not cause the link to be activated, etc. In the case of UI events, this is important for security reasons, as it prevents scripts from simulating user actions that interact with the browser itself.

From http://www.howtocreate.co.uk/tutorials/javascript/domevents.

z00bs
@z00bs - You are right. Now I have changed the way I am handling. I am controlling the focus through code, after enter key is pressed, which is similar to what a tab event would do. The implementation is also at a higher level.
lalit