This topic is the discussion thread for the Vaadin documentation page Text Field component | Vaadin components.
Questions, feedback, and comments are welcome here.
This topic is the discussion thread for the Vaadin documentation page Text Field component | Vaadin components.
Questions, feedback, and comments are welcome here.
How to listen for an event when the user presses enter?
Thanks for that hint. To wrap up the question, here's a concrete example of how to do it:
Shortcuts.addShortcutListener(textField,
e -> System.out.println("Input: =" + textField.getValue()),
Key.ENTER)
.listenOn(textField)
.resetFocusOnActiveElement();
Simpler way:
textField.addKeyUpListener(Key.ENTER, _ -> doStuff());
It seems that the ValueChange Listener does not catch any input to the text field component.
TextField txt1 = new TextField("Test");
txt1.addValueChangeListener(evt -> {
if (evt.getValue() != null && evt.getValue() == "5") {
...
}
});
So, I put the cursor in the txt1, and try to enter 1, 2, 3, 4, 5. Nothing happened.
What is not working for you? Is the listener not called at all? Or just the condition not met?
At least, I see the listener uses an identity check on String value that will most likely fail. You should use `equals` method instead
Alright, I found it. The feature that I need is to change the textfield component ValueChangeMode to EAGER. So that every letter/digit that user enters into the component will trigger ValueChange event.