I would like to be able to have 2 functions, run 1 of them, then inside it, run another and wait for its response before continuing in an if
statement. The response is manual, (yes/no).
Basically something like this
function function1(){
if(function2("Delete", "are you sure", "warning") == true){ //stop here and wait for function2 to return true or false
console.log("yes");
} else {
console.log("no");
}
}
function function2($title, $text, $type){
swal({
title: $title,
text: $text,
type: $type,
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes',
cancelButtonText: 'No, cancel!',
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger',
buttonsStyling: false,
reverseButtons: true
}).then((result) => {
if (result.value) {
return true;
} else if (
// Read more about handling dismissals
result.dismiss === swal.DismissReason.cancel
) {
return false;
}
})
}
What is the cleanest and easiest way to achieve this, in Javascript or JQuery? It can't be instant, as I need the first function to pause and wait for the user response before continuing the function.