2021.2

Table Of Contents
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);
};
Note
When you've used jQuery to register for the events - $(window).on() - you must use
event.originalEvent in the event handler functions, for example:
$(window).on("olcotgsavestate", function(event) {
event.originalEvent.detail.state["mywidget"] = "test";
});
Restoring widgets
When a COTG Form is reopened, the app restores all input fields and widgets that were
already present in the original Form (i.e. the Form deployed via Workflow or sent as test using
the Designer). Dynamically added widgets don't get restored. To restore dynamically added
widgets, you have to:
l Save information that reveals which widgets were added dynamically, and save the
values of their input fields.
This code should go in the event handler for the olcotgsavestate event.
l Add and initialize the widgets again after the Form is reopened. Make sure to put any
saved values back in the HTML.
This code should go in the event handler for the olcotgrestorestate event.
l Trigger the restore-state.cotg event on the newly added widget, to make sure that
it is displayed correctly. For example:
$('#myCamera").trigger('restore-state.cotg',
event.detail.state);
Put this code in the event handler for the olcotgrestorestate. event.
Note that the widget must have the same ID as before in order to be able to retrieve its
state.
For a detailed example, see: "Saving and restoring Camera widgets" on the facing page.
Page 617