Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring the Granularity of Value Change Events #45

Open
vbussol opened this issue Apr 10, 2018 · 0 comments
Open

Configuring the Granularity of Value Change Events #45

vbussol opened this issue Apr 10, 2018 · 0 comments

Comments

@vbussol
Copy link

vbussol commented Apr 10, 2018

Since Vaadin 8 migration, if I use a Stepper (manual input allowed) in a window with a button and a key shortcut, when the user set a value manually and use the shortcut to validate, the stepper value is wrong (initial value).

Could it be possible to have a "ValueChangeMode" like TextField component to control this behavior ? Or any other way to achieve this ?
There may be a workaround I did not find ?

The current behavior seems to correspond to the "ValueChangeMode.BLUR" and I'm looking for the "ValueChangeMode.EAGER". I think the "setImmediate" method did the trick before migration.

Here is an example to illustrate the issue:

public class StepperDialog {
    private final UI parentWindow;
    private final Window stepperWindow;
    private IntStepper stepper;

    public StepperDialog(UI parentWindow) {
        this.parentWindow = parentWindow;
        this.stepperWindow = createWindow();
    }

    public void show() {
        parentWindow.addWindow(stepperWindow);
        stepper.focus();
    }

    private void hide() {
        parentWindow.removeWindow(stepperWindow);
    }

    private Window createWindow() {
        // Create window
        Window window = new Window("StepperDialog");
        window.setModal(true);
        window.setWidth("250px");
        window.setHeight("175px");

        // Root window layout
        VerticalLayout rootLayout = new VerticalLayout();
        window.setContent(rootLayout);

        // Add basic Integer stepper
        stepper = new IntStepper("Stepper");
        stepper.setMinValue(1);
        stepper.setValue(1);
        rootLayout.addComponent(stepper);

        // Add ok and cancel buttons with shortcut
        Button okButton = new Button("OK", event -> validate());
        Button cancelButton = new Button("CANCEL", event -> hide());
        okButton.setClickShortcut(ShortcutAction.KeyCode.ENTER);
        cancelButton.setClickShortcut(ShortcutAction.KeyCode.ESCAPE);
        HorizontalLayout buttons = new HorizontalLayout(okButton, cancelButton);
        rootLayout.addComponent(buttons);

        return window;
    }

    private void validate() {
        Integer value = stepper.getValue();
        System.out.println("value=" + value);
        /**
         * Here, the value is correct if the user click on button and incorrect
         * if he uses the "ENTER" key shortcut.
         */
        hide();
    }

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant