Hi,
Is there any way that from the server-side, I can trigger a Clientside event?
In this app, we use SweetAlert2 to show 'popup' messages to the user. I'd like to trigger that clientside code, but it needs to be done by the server code, not client code.
HTML Element Properties -> Custom Event handlers are triggered by the user doing something in the client browser.
I need something that can be triggered by just serverside code, not a browser event.
Any way this can be done?
Thanks.
Chris.
Can I trigger Client-side Javascript from Server-side code?
Moderators: Jon, Steve, Ian, Dave
-
- Ebase User
- Posts: 22
- Joined: Fri Oct 13, 2017 9:43 am
- Location: Hertford, UK
- Contact:
-
- Ebase User
- Posts: 4
- Joined: Thu Apr 12, 2018 8:44 am
Re: Can I trigger Client-side Javascript from Server-side code?
Hi Chris,
If you want to trigger a SweetAlert popup in response to some condition determined on the server, you'll need to use the Client-Server API.
This requires some code attached to a client-side event via HTML Element Properties -> Custom Event handlers and some server-side code as client-callable functions on the form.
You'd need to break your server-side code into two client-callable functions:
Obviously you can name the functions something a little more descriptive but I'm not sure what it is they're doing.
Then attach client-side code to a click event, something like this:
There's some material on our Resource Hub about Using the Client-Server API.
If you want to trigger a SweetAlert popup in response to some condition determined on the server, you'll need to use the Client-Server API.
This requires some code attached to a client-side event via HTML Element Properties -> Custom Event handlers and some server-side code as client-callable functions on the form.
You'd need to break your server-side code into two client-callable functions:
Code: Select all
function doChecks(){
// do whatever checks you need to do
// return information to the client code so it knows whether to show a prompt
return {
warning: true
}
}
function completeAction(){
// do whatever you need to do to complete the event
}
Then attach client-side code to a click event, something like this:
Code: Select all
// execute the server-side code that does the checks that might result in a warning
var result = $eb.executeFunction("doChecks", null, true, true);
// if there is a warning, show a sweet alert
if(result.warning){
// show the alert, for example..
Swal.fire({
...
}).then((result) => {
if (result.isConfirmed) {
// complete the server-side action
$eb.executeFunction("completeAction", null, true, true);
}
else if (result.isDenied) {
// do nothing? maybe show another alert confirming that the action has been aborted?
}
})
}
else {
// no alert required, complete the action without a prompt
$eb.executeFunction("completeAction", null, true, true);
}
0 x
-
- Ebase User
- Posts: 22
- Joined: Fri Oct 13, 2017 9:43 am
- Location: Hertford, UK
- Contact:
Re: Can I trigger Client-side Javascript from Server-side code?
Hi Sam
Thanks for that advice and code examples.
I'm using client-callable functions that give feedback response elsewhere, so I can base it on that code.
It's just this particular sceanrio is a little bit complex, but I'll use this principle, and give it a go.
Thanks for your help.
Regards,
Chris.
Thanks for that advice and code examples.
I'm using client-callable functions that give feedback response elsewhere, so I can base it on that code.
It's just this particular sceanrio is a little bit complex, but I'll use this principle, and give it a go.
Thanks for your help.
Regards,
Chris.
0 x
-
- Ebase User
- Posts: 6
- Joined: Fri Feb 10, 2017 10:17 pm
Re: Can I trigger Client-side Javascript from Server-side code?
I've done something like this before and used JavaScript to trigger that API call every x mins.
Polling like this may be ok, but I think this is where webSockets come in. It would be good if Verj had this out of the box.
Polling like this may be ok, but I think this is where webSockets come in. It would be good if Verj had this out of the box.
0 x
Who is online
Users browsing this forum: No registered users and 5 guests