3

I have my twitter BootBox open like this:

bootbox.dialog("{{$steps[0]}}"); 

after ten Seconds, I close my BootBox like this:

window.setTimeout(function(){
    bootbox.hideAll();
}, 10000);

Is it possible to show the remaining seconds until close in the BootBox?

Scott
  • 21,211
  • 8
  • 65
  • 72
davidOhara
  • 1,008
  • 5
  • 17
  • 39

1 Answers1

4

You can add a div to your message, like this:

bootbox.dialog("Your message <div id='SecondsRemaining'>10</div>"); 

Then update it using this function:

(function(){
    var remaining = 10; // Number of seconds
    var obj = document.getElementById("SecondsRemaining");
    var timeout = window.setInterval(function(){
        remaining--;
        if(remaining==0) {
            // Time is up, stop the timer and hide the bootbox
            window.clearInterval(timeout);
            bootbox.hideAll();
            return;
        }
        obj.innerHTML = remaining; // Update the value displayed
    }, 1000); // Decrease counter every second
})();

For bootbox 4+ the format has changed. The dialog should be created:

bootbox.dialog({ message: "Your message <div id='SecondsRemaining'>10</div>" }); 
Scott
  • 21,211
  • 8
  • 65
  • 72
  • @Scott I got this error: `Error: Please supply an object of options` You know how I can do to solve it? I'm using Bootbox v4.3 – candlejack Mar 17 '15 at 22:26
  • 1
    @alessadro I have updated the code. You need to provide the content as a `message` parameter. Hope that helps – Scott Mar 18 '15 at 09:09
  • @Scott can you provide the full code? I'm just confused where should I put the function :( – Amirreza Nasiri Jul 05 '15 at 15:27
  • @AmirrezaNasiri That is the full code. Sorry not sure what you still need. If you are having an issue, perhaps start a question. – Scott Jul 05 '15 at 18:36