nuOnLoad keeps triggering

Questions related to using nuBuilder Forte.

nuOnLoad keeps triggering

Postby toms » Thu Jan 11, 2018 1:30 am

Hi,

I added nuOnLoad() in a form's javascript. When the form is opened, the function gets triggered for the first time. (ok so far)
Now the function keeps getting triggered even when I open other forms.

Code: Select all
function nuOnLoad()
{
  console.log("nuOnLoad");
}


Adding a if (window.top === window.self) didn't help either.

Check out my recording that illustrates the issue: https://vimeo.com/250463563
toms
toms
 
Posts: 409
Joined: Wed Nov 08, 2017 8:57 pm

Re: nuOnLoad keeps triggering

Postby admin » Thu Jan 11, 2018 7:56 am

toms,

That is what it is supposed to do. http://wiki.nubuilder.net/nubuilderforte/index.php/Javascript#nuOnLoad

If you want something to run on just 1 Form then just place that code in the Javascript section of the Form... http://wiki.nubuilder.net/nubuilderforte/index.php/Javascript

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

Re: nuOnLoad keeps triggering

Postby toms » Thu Jan 11, 2018 8:05 am

Steven, the code is in the Javascript section of the Form. You can see it in my recording.
toms
toms
 
Posts: 409
Joined: Wed Nov 08, 2017 8:57 pm

Re: nuOnLoad keeps triggering

Postby admin » Thu Jan 11, 2018 8:26 am

toms,

nuOnLoad will stay in memory (as with any Javascript function in Forte) unless you overwrite the nuOnLoad function or do this or set it to null eg.

Code: Select all
nuOnLoad = null


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

Re: nuOnLoad keeps triggering

Postby toms » Thu Jan 11, 2018 3:01 pm

Setting nuOnLoad = null should do the job.

I also noticed that adding nuOnLoad() in a form's javascript will override the nuOnLoad() that is declared in the Header of Setup.
In other words, as soon as the form's nuOnLoad() is initialized, the header's nuOnLoad() does not fire anymore.

To come around this issue, a new event nuLoadGlobal() could be introduced that can be used in the Header of Setup.
toms
toms
 
Posts: 409
Joined: Wed Nov 08, 2017 8:57 pm

Re: nuOnLoad keeps triggering

Postby admin » Fri Jan 12, 2018 3:16 am

toms,

nuOnload() is what you should use to run things globally.

If you want to run something on just one Form, then just put it in the Javascript section of that Form (but not inside a function called nuOnload().)

eg.

Code: Select all
  console.log("nuOnLoad");

Not...
Code: Select all
function nuOnLoad()
{
  console.log("nuOnLoad");
}


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

Re: nuOnLoad keeps triggering

Postby toms » Fri Jan 12, 2018 1:25 pm

Thank you for your clarification!
toms
toms
 
Posts: 409
Joined: Wed Nov 08, 2017 8:57 pm

Re: nuOnLoad keeps triggering

Postby admin » Sat Jan 13, 2018 3:23 am

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


Return to General