Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Bootbox from displaying twice after a double click?

I have a <ul> element that opens a bootbox when it's clicked. Double clicking this element triggers the 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 disabling clicking on the element but both failed. The bootbox still appears twice.

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

Anyone has a suggestion?

like image 434
Varda Elentári Avatar asked Sep 16 '15 20:09

Varda Elentári


2 Answers

Another solution can be to add:

bootbox.hideAll();

to hide any other bootboxes right before showing the bootbox like so:

bootbox.hideAll();
bootbox.confirm("Some Message " , function (result){/*do stuff*/}
like image 149
Varda Elentári Avatar answered Nov 11 '22 02:11

Varda Elentári


Try this:

$("#email-list").on("click", ".list-group-item", function (e) {
   if(!$('#myModal').is(':visible')){
       $('#myModal').modal('show');  
   }
   e.preventDefault();
}
like image 1
Jasper Giscombe Avatar answered Nov 11 '22 01:11

Jasper Giscombe