Pressing enter two times, calls the callback function two times #514

Open
goblinbr opened this Issue May 4, 2016 · 6 comments

Projects

None yet

3 participants

@goblinbr
goblinbr commented May 4, 2016 edited

When you press enter two times really fast the callback function is called two times.

Also occurs when you click two times the confirm button

Example: https://jsfiddle.net/2399n2z8/

I am using Chome 50.0.2661.94 m , also tested with Firefox 43.0.1

@emileber

I'm experiencing this exact problem.

@emileber

Also, spamming the OK button with the mouse calls the callback multiple times.

@emileber

As a workaround, you can set a flag when closing the modal and reset it on hidden.bs.modal event.

var flag = false;
bootbox.confirm("Confirm?", function(conf) {
        if (conf && !flag) {
            flag = true;
            /* ... */
        }
    })
    .on("hidden.bs.modal", function() {
        flag = false;
    });
@emileber

Or as a fix, you can add this snippet somewhere to override bootbox's dialog function:

/**
 * Prevent multiple callback calls when spamming click, 'enter' or 'esc'.
 */
bootbox.dialog = (function(dialog) {
    return function(options) {
        var modal = dialog(options);
        modal.on("hide.bs.modal", function() {
            modal.off("click escape.close.bb");
        });
        return modal;
    };
})(bootbox.dialog);
@makeusabrew
Owner

Definite bug which needs addressing - thanks.

@makeusabrew makeusabrew added the Bug label Sep 23, 2016
@emileber
emileber commented Dec 9, 2016

@makeusabrew The last release is dating, when is the next patch/minor release planned?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment