Call functions in custom template after form load and use global variables
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
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
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
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:
Then, you should be able to get access to it from all other places on the form, for instance, from a button.
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';
Cheers
- Nikita Kurguzov
- Posts: 889
- Joined: Mon Jul 03, 2017
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.
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.
Cheers
-
- Information
-
Who is online
Users browsing this forum: No registered users and 14 guests