nuBeforeSave triggered

Questions related to using nuBuilder Forte.

nuBeforeSave triggered

Postby toms » Fri Jan 26, 2018 7:10 am

Hi,

There's an Object with type "Select" on a form with an onchange event attached.

onchange_event.PNG
onchange_event.PNG (2.75 KiB) Viewed 2232 times


The PHP procedure does nothing but output a debug message: nuDebug("Dummy"). Actually, it can be replaced with any other code.

php_cde.PNG
php_cde.PNG (4.27 KiB) Viewed 2232 times


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.
toms
 

Re: nuBeforeSave triggered

Postby toms » Fri Jan 26, 2018 2:48 pm

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
toms
 

Re: nuBeforeSave triggered

Postby admin » Sat Jan 27, 2018 11:28 am

toms,

I have added a parameter for both nuRunPHP() and nuRunPHPHidden() that will allow you to ignore any nuBeforeSave().

http://wiki.nubuilder.net/nubuilderforte/index.php/Javascript#nuRunPHPHidden

http://wiki.nubuilder.net/nubuilderforte/index.php/Javascript#nuRunPHP

Let me know if they work properly.

Steven
admin
Site Admin
 
Posts: 3157
Joined: Mon Jun 15, 2009 9:53 am

Re: nuBeforeSave triggered

Postby toms » Sat Jan 27, 2018 6:26 pm

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."
toms
 

Re: nuBeforeSave triggered

Postby admin » Sun Jan 28, 2018 2:16 am

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
admin
Site Admin
 
Posts: 3157
Joined: Mon Jun 15, 2009 9:53 am

Re: nuBeforeSave triggered

Postby toms » Sun Jan 28, 2018 5:21 pm

It works now. Thanks!
toms
 

Re: nuBeforeSave triggered

Postby admin » Sun Jan 28, 2018 5:31 pm

.
admin
Site Admin
 
Posts: 3157
Joined: Mon Jun 15, 2009 9:53 am


Return to General