Welcome to the nuBuilder Forums!

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

Including Javascript

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
icoso
Posts: 181
Joined: Sun Feb 07, 2021 11:09 pm
Been thanked: 1 time

Including Javascript

Unread post by icoso »

In reference to a previous couple of posts.

https://forums.nubuilder.cloud/viewtopic.php?f=20&t=10850
and this post on page two:
https://forums.nubuilder.cloud/viewtopic.php?f=20&t=10320

Can I access or load an external Javascript file from within the Custom code of an object?

The reason I'm asking about this is because I found that on a launch form that I have, I have a button that will run some code to erform an SQL search and then call another form to display the results. I found that the Custom code that is allowed seems to be limited in length. As I updated and added code to my Custom code on my button object, the bottoms rows were getting cut off. SO then I thought I would try to move the bulk of my JavaScript to an external file and I added the following code to the beginning of the Custom Code

Code: Select all

<script src="'myjsfile.js" type='text/javascript'></script>
Then when I clicked save I lost my form. I mean it actually disappeared from the forms list. Which means I lost all the code I had in that form. I checked the zzzzsys_object table and could see all of my objects that I had on that form were still there but the form was gone. I checked the zzzzsys_form table and it was gone from there too. So then I copied one of my existing forms and I changed the form_id to the same ID that my lost form had. When I then opened that form none of my objects were showing up. Upon further inspection of the bject list, I seen another ID field for the sob_all_zzzzsys_tab_id field. Then scanning thru the zzzsys_tab table that ID was nowhere to be found as well. so I again copied an existing record, changed the tab_ID and the form_id to the appropriate ID's adn now I got my form back and the objects and I have the code that was on my objects (including the button) but I still lost my code on the form itself. WOuld I find that original form anywhere else in the tables?

The only thing I can correlate to losing the form was the way I typed in the <script src...> tags. I used double quotes around that file name instead of single quotes. Could this have caused the loss of the form?
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Including Javascript

Unread post by kev1n »

Add a reference to your external JS file in nuconfig.php:

Code: Select all

$nuConfigIncludeJS					= '';	//-- Include one or more JavaScript File(s).  E.g. 'myjsfunctions.js' or ['myjsfunctions1.js','myjsfunctions2.js']
icoso
Posts: 181
Joined: Sun Feb 07, 2021 11:09 pm
Been thanked: 1 time

Re: Including Javascript

Unread post by icoso »

That wont work. The JavaScript is only pertinent to the fields on this one form. I don't want or need it loaded globally. The only way taht would work is if I put all the code in a function and then call the function from the Custom Code.

Also, Im now having issues with using Hash Cookies since I lost my form.

Im trying to set a global hash cookie in my forms custom code and then use that global hash cookie in the custom code on a field on that same form. Im getting and undefined message.

For example: on my forms custom code:

Code: Select all

var formsql = 'SQL ';
nuSetProperty('FRM_search', formsql, true);
If then do a JavaScript alert(formsql); in the same custom code right after I set the property it displays the SQL text. If I do this: alert($('#FRM_search').val()); I get undefined. WHY?

Then on one of my fields on that form in the custom code on that field I do this:

Code: Select all

var sql = $('#FRM_search').val();
alert("SQL="+ sql);
I get an undefined for the sql variable. WHY?
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Including Javascript

Unread post by kev1n »

To set: nuSetProperty()

To get: nuGetProperty()

$('#FRM_search') gets a reference to a DOM element, not a Hash Cookie.

But iirc, nuGetProperty() won't work for global hash cookies (client-side retrieval), just on server side.
Can you use nuSetProperty() without setting them to global scope? Or maybe window.yourvariable = 'something' or sessionStorage / sessionStorage to set/get variables?
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Including Javascript

Unread post by kev1n »

icoso wrote:That wont work. The JavaScript is only pertinent to the fields on this one form. I don't want or need it loaded globally. The only way taht would work is if I put all the code in a function and then call the function from the Custom Code.
I'm sure this will work. Functions are only run when they are executed.
Otherwise, try using https://api.jquery.com/jquery.getscript/
Post Reply