Page 1 of 1

Call functions in custom template after form load and use global variables

Posted: 06 Jun 2018
by ragesoft
Hi

i've a basic script in the form (using the "Javascript" button) with some global variables defined and some global functions.
I'm creating a custom namespace with "Type.registerNamespace('MyForm')".

Now i have some functions inside the "global" js (like onsubmit check).

And i have some fields that requiere custom rendering with additional javascript.

I want to use the functions and variables from the global JS and vice versa.

is this possible?

How to trigger the custom field js initiation after the global form js loaded?

for example:
i got a status-field that holding some numbers (1-4)
i got a global variable "MyForm.StatusValues = ["Start", "Waiting", "Approved", "Denied"]"

the status-field is a text field and i use custom template to render it as a dropdown.
After form loaded, i want to call the JavaScript form the custom field to fill up the select with the StatusValues from the global form!

I can put all JS inside the global JS from the form, but i want to split it up into the custom fields js for clarity :)

Re: Call functions in custom template after form load and use global variables

Posted: 06 Jun 2018
by Nikita Kurguzov
Dear ragesoft,
In order to have global access to the functions and variables stored in JS editor, you can specify them to be stored in window object, like this:

Code: Select all

window.myVariable = 'Test';
Then, you should be able to get access to it from all other places on the form, for instance, from a button.

Re: Call functions in custom template after form load and use global variables

Posted: 06 Jun 2018
by ragesoft
Thx. and how to trigger my init-functions on custom fields after form loaded compelty?

Somtetimes the js for the fields load faster then form rendering / init is completed...

Re: Call functions in custom template after form load and use global variables

Posted: 06 Jun 2018
by Nikita Kurguzov
Dear ragesoft,
This is strange, the main JavaScript editor should technically load first, unless you have async requests in there. In this case, it wouldn't, of course. But you should be able to add events and listen to their completion, then run the code.

If the delay is minor, you can always add a timed delay to your scripts, but that is of course not the preferred way.