I have a loop and upon certain condition I am trying to have a Jquery deferred object to wait for user input before continuing or breaking the loop.
If I place the confirm().then(
block before the function confirm(){
it tells me that there are not enough parameters in the confirm function. If I place it after, then the loop is never "paused" waiting for user interaction.
Would appreciate your help.
Thanks
for(...) {
if (condition_that_needs_user_interaction){
function confirm() {
var defer = $.Deferred();
$('<div div="dialogError"></div>').html("Error. Continue?").dialog({
autoOpen: true,
close: function() {
$(this).dialog('destroy');
},
title: '<span style="color: red";>Warning!</span>',
modal: true,
buttons: {
'No': function() {
defer.resolve("no");
$(this).dialog("close");
},
'Yes': function() {
defer.resolve("yes");
$(this).dialog("close");
},
'Apply to All': function() {
defer.resolve("all");
$(this).dialog("close");
}
}
});
return defer.promise();
}
confirm().then(
function (answer) {
if(answer == "No") return false;
else if(answer == "Yes") {
//do something;
} else if (answer == "all") {
//do something;
}
}, function(answer) {
}, function(answer) {
});
} else {
// biz as usual
}
} //end for loop