Page 1 of 1
nuBeforeSave triggered
Posted: Thu Jan 25, 2018 10:40 pm
by toms
Hi,
There's an Object with type "Select" on a form with an onchange event attached.
onchange_event.PNG
The PHP procedure does nothing but output a debug message: nuDebug("Dummy"). Actually, it can be replaced with any other code.
php_cde.PNG
As soon as a value is selected from the dropdown, onchange is fired and hence the PHP code is executed.
Now here is the strange thing: The function nuBeforeSave(), that is declared in the form's javascript, is triggered somehow.
How can I prevent it from triggering? I mean no save action has happend at that time.
Re: nuBeforeSave triggered
Posted: Fri Jan 26, 2018 6:18 am
by toms
Simplified example to replicate the issue:
1. In the Javascript section of a Form add;
Code: Select all
if (nuFormType() == 'edit') {
nuAddActionButton('nuRunPHPHidden', 'Try me!', 'nuRunPHPHidden("dummy")'); //-- run any php code (hidden)
}
function nuBeforeSave() {
alert("nuBeforeSave");
}
2. Click the "Try me!" button
3. You'll see an alert 'uBeforeSave' because nuBeforeSave gets triggered for some unknown reason
Re: nuBeforeSave triggered
Posted: Sat Jan 27, 2018 2:58 am
by admin
toms,
I have added a parameter for both
nuRunPHP() and
nuRunPHPHidden() that will allow you to ignore any nuBeforeSave().
http://wiki.nubuilder.net/nubuilderfort ... nPHPHidden
http://wiki.nubuilder.net/nubuilderfort ... t#nuRunPHP
Let me know if they work properly.
Steven
Re: nuBeforeSave triggered
Posted: Sat Jan 27, 2018 9:56 am
by toms
Steven,
I just tested nuRunPHPHidden() and nuBeforeSave() doesn't trigger anymore.
However, I find the description on the wiki not very clear. Looking at the source code, I figured that I can basically pass any parameter (like 1 to indicate true)
"string2 : optional, if this 2nd parameter is passed, any nuBeforeSave() function will not be run."
Re: nuBeforeSave triggered
Posted: Sat Jan 27, 2018 5:46 pm
by admin
toms,
My fault, it was working the opposite way it was supposed to.
So the wiki should make sense now.
If you have a better explanation of how it works, I'll put that on the wiki.
I've updated Github.
Let me know if it works now.
Steven
Re: nuBeforeSave triggered
Posted: Sun Jan 28, 2018 8:51 am
by toms
It works now. Thanks!
Re: nuBeforeSave triggered
Posted: Sun Jan 28, 2018 9:01 am
by admin
.