Welcome to the nuBuilder Forums!

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

nuOnLoad() event

Questions related to using nuBuilder Forte.
Post Reply
alf1976
Posts: 75
Joined: Tue Dec 26, 2017 8:58 pm

nuOnLoad() event

Unread post by alf1976 »

Hi Steven,

i have a few forms that require a bit of setup before they are displayed. Up to now i have been adding a nuOnLoad() function into each form's javascript.
At first i thought i had discovered a bug but in retrospect upon reading the documentation i don't think i have.

So on one of my form's if it is a new record and it is in edit mode, the forms nuOnLoad() removes two tabs. It worked fine until i clicked back to the user home and it wiped out my tabs there too.
After adding a couple of console.log functions i realised that the form's nuOnLoad() was firing when going to any form that was in Edit mode with a record of ID of -1.

This makes sense after reading the wiki as you state that this function is best added to the header setup.
I have got around the problem by adding an if statement within the forms nuOnload() to test the form_id property from nuCurrentProperties().

I much to prefer to add code to the relevant form as it makes them easier to follow and update at a later stage.
So i wonder if in future if this can only altered so that if a form has a nuOnLoad() function it only run on that form by default.

Andrew
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: nuOnLoad() event

Unread post by admin »

Andrew,

If you want to run something on just one Form, simply put it in the Javascript of that Form.

This Javascript will run every time the Form loads or reloads.

There is no need to put it in the nuLoad() function.

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

Re: nuOnLoad() event

Unread post by toms »

Andrew,

I had asked myself the same question in this topic:
http://forums.nubuilder.cloud/viewtopic.php?f=19&t=9216

I found Steven's answer to my question useful:
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().)
In other words, use nuOnload() only under Home ► Setup► Header.

In addition to what has been said I must add that one should also check the Form Type (browse or edit Form) to make sure that scripts run only in either of these two form types.

(In nuBuilderPro you had to use nuLoadBrowse() and nuLoadEdit() to make the distinction)

Code: Select all

if (nuFormType() == 'edit') {
    // Edit Form
} 
else {
 // Browse Form
}





alf1976
Posts: 75
Joined: Tue Dec 26, 2017 8:58 pm

Re: nuOnLoad() event

Unread post by alf1976 »

Thanks toms and Steven,

Didn't realise that it worked like that. I will amend my code.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: nuOnLoad() event

Unread post by admin »

.
Post Reply