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

Prevent multiple button clicks #18

Open
russellhoff opened this issue Jul 26, 2016 · 2 comments
Open

Prevent multiple button clicks #18

russellhoff opened this issue Jul 26, 2016 · 2 comments

Comments

@russellhoff
Copy link

Is there any way to prevent the user from clicking several times a button? I mean, I've proven that the user can click several times a button in a short time (0,5 seconds).

Would it be possible to lock every buttons of the wizard just after the user clicks one, and then, when the new step is shown, enable every button?

@russellhoff
Copy link
Author

Perhaps it'd be a nice feature to add a modal window (loading) to appear when a button is clicked, and hide it when the new Step is shown.

@ldelaprade
Copy link

Created a PaceMaker class for that:

/**
 * JetPlaceMaker to use for Action/Function calls regulation
 * For example to prevent fast clicking causing multiple calls
 */
public class JetPaceMaker
{
    // default minimal time between 2 calls
    private long minimalInterval = 1000;
    private LocalDateTime lastCallTime = LocalDateTime.now();

    public JetPaceMaker() {}
    public JetPaceMaker(long interval)
    {
        minimalInterval=interval;
    }

    public boolean CanDoActionNow()
    {
        LocalDateTime now = LocalDateTime.now();
        long diffInMilli = java.time.Duration.between(lastCallTime, now).toMillis();
        // remember last call time
        lastCallTime=now;
        // return TRUE when enough time elapsed
        if (diffInMilli >= minimalInterval)
            return true;
        else
            Notification.show("Slow down please...");
        return false;
    }
}

Then, modified Wizard Class code adding a private PaceMaker

// Use JetPaceMaker to prevent fast clicks on Wizard Buttons
private JetPaceMaker fastClickPrevention = new JetPaceMaker();

And using it to control clicks pace (for each button. Here the 'Next' button change)

private void initControlButtons()
{
    nextButton = new Button("Next");
    nextButton.addClickListener
    (
        new Button.ClickListener()
        {
            @Override
            public void buttonClick(ClickEvent event)
            {
                if( fastClickPrevention.CanDoActionNow() )
                    next();
            }
        }
    );

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

2 participants