Search code examples
javajavascriptsmartgwt

Globally Disable Tab Key on Page


How can I globally disable the use of the tab key on page? I found this question, but it uses jQuery and I am not using jQuery. I know I can set tabIndex equal to -1 to disable keyboard focus, but this is for a GWT web application that uses GWT-Ext, mixed with SmartGWT, and OpenLayers so it would be easier to just set it once in the page for the entire set of controls (and there are over a hundred different controls).


Solution

  • I ended up having to add this in my EntryPoint class using SmartGWT:

    Event.addNativePreviewHandler(new NativePreviewHandler()
    {
       @Override
       public void onPreviewNativeEvent(NativePreviewEvent event)
       {
          // tab is key 9
          if (event.getNativeEvent().getKeyCode() == 9)
          {
             event.cancel();
          }
       }
    });