Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enter press event for vaadin 10 TextField

Is there any specific way to add shortcut Listener for the Enter Key on a specific TextField element in Vaadin Flow. The documentation is silent about this.

like image 615
Aiden Avatar asked Mar 07 '23 06:03

Aiden


1 Answers

I guess you are not actually looking for a ”shortcut” key but to react to enter presses when the focus is inside the field? If so, see KeyNotifier and e.g. addKeyPressListener.

It is also possible to listen to any DOM event using the element API, e.g.

textField.getElement().addEventListener("keyup", e -> { 
    System.out.println("Value is now: " + 
        e.getEventData().getString("element.value"));
}).addEventData("element.value").setFilter("event.keyCode == 13");
like image 133
Artur Signell Avatar answered Apr 09 '23 01:04

Artur Signell