nuOnLoad() event

Questions related to using nuBuilder Forte.

nuOnLoad() event

Postby alf1976 » Sat Feb 03, 2018 7:12 am

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
alf1976
 
Posts: 75
Joined: Wed Dec 27, 2017 5:28 am

Re: nuOnLoad() event

Postby admin » Sat Feb 03, 2018 8:52 am

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

Re: nuOnLoad() event

Postby toms » Sat Feb 03, 2018 1:20 pm

Andrew,

I had asked myself the same question in this topic:
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
}





toms
 

Re: nuOnLoad() event

Postby alf1976 » Sat Feb 03, 2018 6:19 pm

Thanks toms and Steven,

Didn't realise that it worked like that. I will amend my code.
alf1976
 
Posts: 75
Joined: Wed Dec 27, 2017 5:28 am

Re: nuOnLoad() event

Postby admin » Sat Feb 03, 2018 11:22 pm

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


Return to General