2022.1

Table Of Contents
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" below.
Example
Saving and restoring Camera widgets
This example demonstrates a way to save and restore dynamically added Camera widgets.
How to add Camera widgets is explained in another topic: "Dynamically adding COTG
widgets" on page642.
Page 648