how to block KeyCode.ENTER shortcut

I have a windows with some controls and a OK button that handles the KeyCode.ENTER shortcut
when I press the Enter button the button is automatically pressed and the window accepts the edited by the user values and closes.

My problem is that I want to insert a RichTextArea field inside the window, that needs to handle the Enter (when it has focus) by itself.

As it is now, when I press Enter, the event is handled by the button and the RichTextArea can’t block it.

How could I block the closing of the window when I have focus on my RichTextArea and use it to edit my text there ?

I think I read somewhere that the shortcuts were dependent on the currently focused Panel (and Window as they are panels too).
You could try wrapping your text area in a panel and see if it works.

Thank you,
I checked it and it is true.

Is this my only sollusion?
because now I have a layout problem, since the RichTextArea should be inside a

and the wrapping Panel
arranges the caption on the top
instead of the left (like the other components in the Form

Create a custom field class for such a wrapped RichTextArea using FieldWrapper from the
CustomField add-on
. If I remember correctly, FieldWrapper handles captions in a way compatible with the form rather than forwarding them to the Panel. Use null as the caption of the Panel and the wrapped RichTextField so that they won’t be shown.

This produces a somewhat suboptimal DOM structure but should be relatively easy to set up without making client side customizations.

I don’t know of any other way. Sorry.

As a workaround, could you set the caption on the wrapping layout instead on the text area ?
Like this it would be handled by the form and be displayed on the left.

Is there a posibility to get the event from Enter key (inside a Form or a Window) and decide what you want to do later, depending the situatuon?

The same question from me. Could somebody answer?

There is another way that I just tested. It will work for you if you have a factory for all the text areas that you generate.

  1. Attach focus/blur listeners to all text areas.
  2. On focus, change the click shortcut of your button from ENTER to Shift+ENTER (for example). Restore on blur.

I’m notifying our button owner of focus/blur events using an event bus; for you, registering to the right observer may be harder. You may want to use the Application object as a hub.

In any case, this is a basic usability issue that Vaadin should just fix. These workarounds are hideous.

create a ticket
if there isn’t one yet.