2021.2

Table Of Contents
The following code combines the previously saved string with the restored URL of a (static)
COTG Camera element:
window.addEventListener("olcotgrestorestate", function(event) {
var value = event.detail.state["myString"];
value = value + $("#camera1 img").attr("src");
$("form p").html(value);
};
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569). 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";
});
Page 616