Make CallBack run directly

0

I got a BootBox API just for the prompt , but the problem is that in this syntax it has a callback and with it, it only runs the code the second time that I click the button. Of course, I wanted him to execute on the first click. (with the normal prompt in JavaScript works the way I want, but that's awful prompt )

Follow the code:

function valida2(){
  bootbox.prompt({
    title: "This is a prompt with a number input!",
    inputType: 'number',
    callback: function (result) {
         Tips = parseInt(result);
         console.log(Tips);


    }
});
}


//a função que chama esse prompt
function ccck(){ 

 valida2();
 myArray[count] = [count + 1, 1 , Tips, "-"];
 sum += Tips;  
}
    
asked by anonymous 26.06.2017 / 18:02

1 answer

0

As you said well, "The point is that the code continues" , so you have to redirect the application flow to continue after the callback:

function valida2(done) {
  bootbox.prompt({
    title: "This is a prompt with a number input!",
    inputType: 'number',
    callback: done
  });
}


//a função que chama esse prompt
function ccck() {

  valida2(function(result) {
    // o fluxo da aplicação continua aqui:
    var Tips = parseInt(result);
    myArray[count] = [count + 1, 1, Tips, "-"];
    sum += Tips;
  });

}

So your code remains within the callback, ie when the result is available.

    
26.06.2017 / 19:13