This topic is locked

Sweetalerts - different methods

1/9/2021 8:17:45 PM
PHPRunner General questions
D
david22585 author

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.

D
david22585 author 1/17/2021

I just wanted to add another one to the list, using sweetalerts with errors.
Events -> Before record added/updated

if ($values["value"] == "some kind of data"){

// Shows the error message at the top of the page as well like how PHPRunner normally does

$message = "This is a sample error message";

// Proxy for the sweet alert

$pageObject->setProxyValue("error", "Insert any error message here");

return false;

} else {

return true;

}


JavaScript OnLoad Event

if (proxy["error"]){

swal({

title: "Error",

text: "proxy["error"]",

icon: "error",

button: "Okay",

timer: 5000,

});

}


If you had multiple checks on the data, it would be like this:

if ($values["name"] == ""){

$message = "Your name cannot be blank";

$pageObject->setProxyValue("error", "Your name cannot be blank");

return false;

} else if ($values["email"] == "something"){

$message = "Invalid email address";

$pageObject->setProxyValue("error", "Invalid email address");

return false;

{ else if ($values["address"] == "wrong_data3"){

$message = "Address must be valid";

$pageObject->setProxyValue("error", "Please use your proper address");

return false;

} else {

return true;

}
A
acpan 1/17/2021

Thank you David, i just started to explore this with your guide. Your guide is very useful.

It is a nice add-on for PHPRunner!

A
AlphaBase 3/3/2021



[color="#1C2837"]

[/size]
[/b][/size][/font][/b][/size][/font][/color]

[color="#1C2837"]

[/size][/color]