How to prevent Bootbox from loading twice after double-clicking?

I have an element <ul>that opens the boot box when clicked. Double-clicking on this item launches onclick in jQuery twice

$("#email-list").on("click", ".list-group-item", function (e) {
bootbox.confirm("Send a forgotten password email to " + email + "?", function (result) {...}}

I tried using 'e.preventDefault ()'

$(document).ready(function () {

    $("#email-list").dblclick(function (e) {

        e.preventDefault();
    });

});

I even tried to disable clicking on an element, but both failed. The boot box is still displayed twice.

$("#email-list").bind('click', function () { return false; });
//...do stuff
$("#email-list").unbind('click');

Anyone have a suggestion?

+4
source share
4 answers

Another solution might be to add:

bootbox.hideAll();

to hide any other boot boxes right before showing the boot box as follows:

bootbox.hideAll();
bootbox.confirm("Some Message " , function (result){/*do stuff*/}
+5
source

Try the following:

$("#email-list").on("click", ".list-group-item", function (e) {
   if(!$('#myModal').is(':visible')){
       $('#myModal').modal('show');  
   }
   e.preventDefault();
}
+1

click,

e.preventDefault(); 

e.stopPropagation(); 

return false;
0

I decided that the best way to do this is to separate the two events; onclick and dbclick, I used something like this, hope this saves time:

var DELAY = 700, clicks = 0, timer = null;

    $(function () {

        $("#email-list").on("click", ".list-group-item", function (e) {

            clicks++;  //count clicks

            if (clicks == 1) {
                   //do stuff
                    clicks = 0;  //after action performed, reset counter

                }, DELAY);
            } else {

                clearTimeout(timer);    //prevent single-click action
                clicks = 0;             //after action performed, reset counter
                return false;
            }

        })
        .on("dblclick", function (e) {
            e.preventDefault();  //cancel system double-click event
        });
   }
0
source

Source: https://habr.com/ru/post/1607714/


All Articles