This topic is locked
[SOLVED]

'Submit not defined' in Sweet Alert FIeld Event

6/30/2025 8:35:27 AM
PHPRunner General questions
D
druck281 author

In v10.91, I have the following ClientBefore on a Field Event and it works fine.

params["value"] = this.getValue();
//Prompt user to choose if they want to update Presented Date on all Awards associated with this banquet
Swal.fire({
title: 'Update Presented Date',
icon: 'question',
text: 'Would you like to update the Presented Date for all Awards associated with this Banquet?',
showDenyButton: true,
confirmButtonText: 'Update All',
confirmButtonColor: '#02c408',
allowOutsideClick: false, //Disable the ability to click off of the popup which would bypass the page reload
allowEscapeKey: false,
denyButtonText: 'Leave As-is'
}).then(function(result) {
if (result.isConfirmed){ //Approve button was clicked
params["change"]=1;
submit();
} else if (result.isDenied) { //Deny button was clicked
params["change"]=0;
submit();
}
});
return false;

Using the same code in v11, the Sweet Alert appears but regardless which button I click on, I get the following error in the console:

Uncaught (in promise) ReferenceError: submit is not defined

AI has me trying all sorts of different things to define submit, most recently the following but so far, nothing will get the server/clientAfter events to fire.

params.value = this.getValue();

// Get the correct submission function for PHPRunner v11
const submitAction = () => {
// Try all possible submission methods in order
if (typeof Runner !== 'undefined' && Runner.page && Runner.page.submitForm) {
Runner.page.submitForm();
}
else if (typeof controls !== 'undefined' && controls.save) {
controls.save();
}
else {
// Fallback to standard form submission
document.querySelector('form').submit();
}
};

Swal.fire({
title: 'Update Presented Date',
icon: 'question',
text: 'Would you like to update the Presented Date for all Awards associated with this Banquet?',
showDenyButton: true,
confirmButtonText: 'Update All',
confirmButtonColor: '#02c408',
allowOutsideClick: false,
allowEscapeKey: false,
denyButtonText: 'Leave As-is'
}).then((result) => {
if (result.isConfirmed) {
params.change = 1;
submitAction();
} else if (result.isDenied) {
params.change = 0;
submitAction();
}
});

return false;

Has anyone else had trouble with using a Sweet Alert in a Field Event that needs to continue to the server event? It works flawlessly in a Custom Button but it won't work in a Field Event.

Thanks!

C
copper21 6/30/2025

I just wrote something similar. There are a few differences between mine and yours. I am using V11. Try this out:

params["value"] = this.getValue();

//Prompt user to choose if they want to update Presented Date on all Awards associated with this banquet

Swal.fire({
title: 'Update Presented Date',
icon: 'question',
text: 'Would you like to update the Presented Date for all Awards associated with this Banquet?',
showDenyButton: true,
confirmButtonText: 'Update All',
confirmButtonColor: '#02c408',
allowOutsideClick: false, //Disable the ability to click off of the popup which would bypass the page reload
allowEscapeKey: false,
denyButtonText: 'Leave As-is'
}).then((result) => {
if (result.isConfirmed){ //Approve button was clicked
params["change"]=1;
submit();
} else if (result.isDenied) { //Deny button was clicked
params["change"]=0;
submit();
}
});
return false;

G
Grdimitris 6/30/2025

PHPRunner 11 has newer Sweetalert 2 version and I had similar problem with Swal.showLoading() and proposed me this
Swal.fire({
title: 'Loading data, please wait...',
allowOutsideClick: false,
allowEscapeKey: false,
allowEnterKey: false,
showConfirmButton: false,
didOpen: () => Swal.showLoading()
});
and worked

So I asked ChatGPT your problem and answered
"In PHPRunner the routine that actually posts back to the server after an asynchronous task (your SweetAlert) isn’t called submitAction() – it’s either submit() or (equivalently) ajax.submit(), and you must return false from your ClientBefore event so that the built-in form submission is deferred until after your callback runs.

Here’s how you can rewrite your code in the ClientBefore event of your custom button:

// ClientBefore event
Swal.fire({
title: 'Update Presented Date',
icon: 'question',
text: 'Would you like to update the Presented Date for all Awards associated with this Banquet?',
showDenyButton: true,
confirmButtonText: 'Update All',
confirmButtonColor: '#02c408',
denyButtonText: 'Leave As-is',
allowOutsideClick: false,
allowEscapeKey: false
})
.then((result) => {
// toggle your parameter
params.change = result.isConfirmed ? 1 : 0;
// submit to the Server event
submit(); // or: ajax.submit();
});

// return false to postpone the default submission
return false;

submit() (or ajax.submit()) is the PHPRunner AJAX helper that hands control back to the Server event after an async task finishes
xlinesoft.com
.

Without the return false; at the end, PHPRunner will immediately run the Server event before your then() callback ever fires.

If you really want to keep a named wrapper, you could do:

function submitAction() {
submit(); // or ajax.submit();
}

// …in your Swal callback…
submitAction();

but it’s usually simplest to call submit() (or ajax.submit()) directly."

D
druck281 author 6/30/2025

So in my original code, I did return false and used submit() in an attempt to continue to the server event. After reading through the responses, I decided to try the simplest solution first and it actually worked. Thank you both for your help!

One simple change and the code worked...
Instead of using submit();, I changed it to ajax.submit();