So I've been playing with Sweetalerts, and trying to get them to work for numerous situations. I believe I got them to all work, with some quirky methods for a few, but I would like some others to test these out or maybe make some suggestions to make them work better so everyone can utilize them. I'm going to go through each scenario I can think of on here, and if I forgot any, please let me know. All of this code will be on the events tab
Inline Add/Edit
Lets say that you want a popup after an inline add on the list page that says user data has been entered.
List Page -> JavaScript Onload Event
function funcAfter(){
swal({
title: "Your account data has been successfully added.",
icon: "success",
button: "Okay",
timer: 5000,
});
}
this.on('afterInlineAdd', funcAfter);
If you want use this with an Inline Edit event, add another function name, say funcEdit, and call that function but edit afterInlineAdd to afterInlineEdit.
Add/Edit data, but stay on the Add/Edit Page
This will work when you add or edit data, and stay on the add page or stay on the edit page.
Add/Edit Page -> After Record Added/Updated event (This MAY or MAY NOT be needed)
$pageObject->stopPRG = true;
$pageObject->setProxyValue("saved", true);
Add/Edit Page -> JavaScript Onload Event
if (proxy["saved"]){
swal({
title: "Your account data has been successfully updated.",
icon: "success",
button: "Okay",
timer: 5000,
});
}
Add/Edit data, but go to the view page after add/edit
This one was the biggest pain, and I'm sure there is a better way to make this work, but this is what I had to do to get this to work.
Add Page -> After Record Added
$_SESSION["swal"] = "true";
This is going to temporarily save a session variable to use later.
View Page -> Before Display
if ($_SESSION["swal"] == 'true'){
$pageObject->setProxyValue("swal", $_SESSION["swal"]);
unset($_SESSION["swal"]);
}
This will look to see if there is a SESSION with the true data, and if there is, set a proxy value and unset the session.
View Page -> JavaScript Online
if (proxy["swal"] == "true"){
swal({
title: "Your account data has been successfully updated.",
icon: "success",
button: "Okay",
timer: 5000,
});
}
If there is a proxy value, then it will fire the sweetalert code.
The last one could also be used on the list page as well if you go to the list page after adding or editing a record.
I would like to use this as a starting point to make better use of the sweetalerts for everyone. If anyone has other methods to make it all work, or if this doesn't work, lets figure out a solution within the community to make all of our projects a little more beautiful.