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.