Search code examples
javascriptbootbox

Bootbox prompt not working as it should


When ever i use bootbox prompt, the script does not pause for a while to accept input from a user like javascript prompt works, The whole program runs without getting an input from a user. i am not sure why? Any help is appreciable.

this.num = bootbox.prompt("Enter a number of nodes" , function(result)
        {
            if(result == null)
            {
                console.log("Cancelled");
            }else{

                return result;
            }
        });

        console.log(this.num); 

Solution

  • Bootbox dialogs are not blocking events, so everything that needs to happen only when the dialog is dismissed needs to be in the callback function.

    This is covered on the Bootbox site:

    The only required argument for alert calls is message; callback is required for confirm and prompt calls in order to determine what the user's response was. Even when calling alert a callback is useful to determine when the user dismissed the dialog since our wrapper methods can't & don't block like their native counterparts; they are asynchronous rather than synchronous.

    This will be true of any non-native modals, not just Bootbox (and the underlying Bootstrap modals).