Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

nuOnLoad keeps triggering

Questions related to using nuBuilder Forte.
Locked
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

nuOnLoad keeps triggering

Unread post by toms »

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
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: nuOnLoad keeps triggering

Unread post by admin »

toms,

That is what it is supposed to do. http://wiki.nubuilder.net/nubuilderfort ... t#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/nubuilderfort ... Javascript

Steven
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: nuOnLoad keeps triggering

Unread post by toms »

Steven, the code is in the Javascript section of the Form. You can see it in my recording.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: nuOnLoad keeps triggering

Unread post by admin »

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
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: nuOnLoad keeps triggering

Unread post by toms »

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.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: nuOnLoad keeps triggering

Unread post by admin »

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
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: nuOnLoad keeps triggering

Unread post by toms »

Thank you for your clarification!
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: nuOnLoad keeps triggering

Unread post by admin »

.
Locked