This topic is locked
[SOLVED]

Using Sweet Alert in OnBefore function of a tri-part event

10/11/2022 8:54:43 AM
ASPRunner.NET General questions
Pete K author

I want to replace the generic JS confirm dialog with a Sweet Alert to get confirmation to proceed with the server event. But nothing I've tried has worked. The alert box works as expected; the problem is control passes to the server event before the user responds to the alert, so I have no way of getting the response to the server event. The code below is copied from the ASPRunner documentation; I only added the setting of the "continue" param, which I expected to be evaulated on the server. But execution appears to fall to the default case as soon as the dialog is generated.

Is there a way to make this swal alert behave like the JS confirm dialog, that is, to pause execution until the user responds?

swal("Would you like to delete this record?", {
buttons: {
cancel: "Nope",
proceed: {
text: "Yes, please",
value: "proceed",
}
},
})
.then( function(value) {
switch (value) {

case "proceed":
params["continue"] = true;
swal("Thanks, I'll go ahead");
break;

default:
params["continue"] = false;
swal("Gotcha!");
break;
}
});
S
Steve Seymour 10/11/2022

This is the code that I use to get the user confirm that they want to send an Invoice to the customer...
This is placed in the Before Client Button tri event. Alter the words to suit your needs.

swal("Create Invoice and Send to Customer ?", {
buttons: {
cancel: "No",
proceed: {
text: "Yes",
value: "proceed",
}
},
})
.then((value) => {
switch (value) {

case "proceed":
submit();
break;

default:
swal("Cancelled.");
break;
}
});
return false;

Pete K author 10/12/2022

Thank you. That works. Now I see how the logic works. You always return false to prevent the flow from continuing until you want it to, then you force it by using submit(). It makes perfect sense to me now. Appreciate the help.

—Pete