So I am very new to these Promises. I am having a hard time wrapping my head around them. I have looked over plenty of tuts and SO posts, but haven't come across anything like my situation. Here is my current code.
$("#PayNow, input[name^='schedulepmt']").on("blur", function(){
var diff = 0;
diff = calcBalanceDue();
if(diff){
$.when(confirmNewPayment(diff)).then(function(){
if($(this).attr("id") === "PayNow" && input[name^='schedulepmt'].length && ($(this).val() !== $(this).data("prevValue"))){
if(!resetPmtInfo()) {
$(this).val($(this).data("prevValue"));
}
}
});
}
});
I would like the code inside the .then() to execute after confirmNewPayment() has executed. It seems to be still all running async.
Thanks.
Here is confirmNewPayment()
function confirmNewPayment(diff){
bootbox.dialog({
message: "There is an outstanding balance. How would you like to proceed?",
title: "Outstanding Balance Options",
closeButton: false,
buttons: {
addpmt: {
label: "Add a scheduled CC payment",
className: "btn-success",
callback: function() {
scheduledPmtData.PaymentCount += 1;
$("#ScheduledPayments").append($("#ScheduledPmtTemplate").render(scheduledPmtData,{amount:diff}));
}
},
collect: {
label: "Mark balance as \"To Collect\"",
className: "btn-primary",
callback: function() {
$("#BalanceDueRow").removeClass("hide");
$("#BalanceDue").val(diff);
}
}
}
});
}
confirmNewPaymentlook like? Why are you calling$.whenon it? Does it return a promise?confirmNewPaymentis async? When do you want the.thento run? After the dialog opens? After a button is clicked?