Context: In a Vaadin 23.2.8 form there is a TextField and a Button.
What I want to do / expected behavior: In the ValueChangeListener of the TextField there should open a dialog. The dialog should be visible until the user closes it. The button should execute in the background (or after the user closes the dialog, which would also be fine).
Unexpected behavior: When a user types something into the TextField and clicks at the button, then the dialog pops up and vanishes after a fraction of a second. And the button is not executed.
What does work: When the user types something into the TextField, then leaves the TextField (by clicking somewhere outside the TextField) and then clicks the button, everything works as expected.
Code / Small reproducible example:
@Route("sandbox")
public class SandboxView extends VerticalLayout {
public SandboxView() {
TextField textfield = new TextField("1. Type something");
textfield.addValueChangeListener(event -> {
new Dialog(new Text("Some text in dialog")).open();
});
this.add(textfield);
Button button = new Button("2. Click me");
button.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
button.setDisableOnClick(true);
button.addClickListener(event -> {
System.out.println("Button was clicked");
button.setEnabled(true);
});
this.add(button);
}
}
Questions:
- Is it forbidden to open a Dialog in a ValueChangeListener in Vaadin?
- What can I do to get the expected behavior?