2021.2

Table Of Contents
$('#' + cameraID).cotgPhotoWidget(); // init COTG widget
}
Saving and restoring custom data and widgets
The Capture OnTheGo (COTG) app stores the values of the input fields to the local repository
of the app upon closing the Form. On reopening the Form the original input fields and their
values are restored. However, dynamically added widgets (see "Dynamically adding COTG
widgets" on page611) don't get restored. This needs to be handled in code. This topic explains
how to do that.
Adding event listeners
In the process of closing and opening a Form two important events are triggered by the COTG
library:
l olcotgsavestate. This event is meant for custom scripts to save information when the
user closes or submits the Form. It occurs after the state of all static input fields has been
saved.
l olcotgrestorestate. This event allows custom scripts to do something when the Form is
reopened. It occurs after all static inputs have been restored.
To latch on to these events, you have to register a olcotgsavestate listener and a
olcotgrestorestate listener, respectively, on the window object. The window object represents a
window containing a DOM (document object model), in this case the COTG Form.
The function callback on its addEventListener method allows you to implement custom code as
part of the save and restore processes.
(For more information about the addEventListener method see the documentation: Mozilla and
w3schools.)
The following code registers the olcotgsavestate listener on the window object.
window.addEventListener('olcotgsavestate', function(event) {
/* code to save custom data */
});
The following snippet does the same for the restore process.
window.addEventListener('olcotgrestorestate', function(event) {
/* code to retrieve custom data and restore custom widgets */
});
Page 615