Mike
Mike

Reputation: 1336

GWT cancel a keypress event in a RichTextBox

I would like to cancel a particular keypress event in a RichTextBox.

Here it is described how to do it in a regular TextBox, but it doesn't work in a RichTextArea because it doesn't have the cancelKey() method.

Here's my code:

   RichTextArea richTextArea = new RichTextArea();
   ...
   richTextArea.addKeyPressHandler(new KeyPressHandler() {

        @Override
        public void onKeyPress(KeyPressEvent arg0) {
            if (arg0.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                // Here is where I would like to prevent the ENTER key from going to the richTextBox
            }
        }
    });

Upvotes: 0

Views: 933

Answers (1)

Suresh Atta
Suresh Atta

Reputation: 121998

Try this working fine for me ...

  RichTextArea richTextArea = new RichTextArea();
       richTextArea.addKeyPressHandler(new KeyPressHandler() {

            @Override
            public void onKeyPress(KeyPressEvent arg0) {
                if (arg0.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
                    arg0.getNativeEvent().preventDefault();
                }
            }
        });

Upvotes: 2

Related Questions