2022.1

Table Of Contents
Note
You should not register for these events after the document has loaded (e.g. on the
$(document).ready() event), because these events might get triggered before the
document is ready.
Place your code in a separate JavaScript file and make sure to include that file in the Web
context or in the Web section that contains the COTG Form (see "Including a JavaScript file in a
Web context" on page600). For this file, the order in which JavaScript files are included in the
template doesn't matter.
Handling the save and restore events
The code inside the function callback of the added event listeners should respond to the event,
by saving or retrieving custom information, respectively.
When the COTG app saves the Form, you can store extra information in the
event.detail.state object as follows:
event.detail.state["key"] = value;
The key can be any string, as long as that string isn't the same as the ID of one of the widgets
on the Form.
In the code that handles the olcotgrestorestate event, use the same key to retrieve the stored
information.
The following sample saves the value "test" using "myString" as the key, when the Form is
saved:
window.addEventListener("olcotgsavestate", function(event) {
event.detail.state["myString"] = "test";
});
The following code retrieves the value that was stored with the myString key and displays it in a
paragraph (a <p> element) at the top of the form.
window.addEventListener("olcotgrestorestate", function(event) {
var value = event.detail.state["myString"];
$("form p").html(value);
};
Page 647