Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
Wait For Response Before Continuing - Like Prompt()

I have a function that relies on a confirm.js prompt input. I want the function to wait for the input to be fulfilled prior to continuing anymore. In the same way prompt() waits for the ok button to be pressed, I want my function to wait for a button click event before it returns and proceeds.

Right now I attempted a Promise (not familiar at all):

function dostuff(){
    return new Promise(function(resolve, reject) {
        $.confirm({
            content: '<input id="input">',
            buttons: {
                done: {
                    text: 'Done',
                    action: () => {
                        resolve(); // resolve promise when button is pressed
                    }
                }
            }
        });
    }).then(function(){
      return input.val();
    });
  }
}

But using the function doesn't pause the execution of the remaining script. For example:

console.log("start")
dostuff().then(function(result) {
    console.log(result);
});
console.log("end")

Will print:

start
end
undefined

Then finally the input value once I've pressed enter.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda