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

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
ragesoft
Posts: 50
Joined: Fri Feb 23, 2018

06 Jun 2018

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 :)

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

06 Jun 2018

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.
Cheers

ragesoft
Posts: 50
Joined: Fri Feb 23, 2018

06 Jun 2018

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...

User avatar
Nikita Kurguzov
Posts: 889
Joined: Mon Jul 03, 2017

06 Jun 2018

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.
Cheers

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 24 guests