2022.2

Table Of Contents
window.addEventListener("olcotgrestorestate", function(event) {
var value = event.detail.state["myString"];
$("form p").html(value);
};
Note: Whenyou'veusedjQuerytoregisterfortheevents-$(window).on()-youmustuse
event.originalEventintheeventhandlerfunctions,forexample:
$(window).on("olcotgsavestate", function(event) {
event.originalEvent.detail.state["mywidget"] = "test";
});
Restoringwidgets
WhenaCOTGFormisreopened,theapprestoresallinputfieldsandwidgetsthatwerealready
presentintheoriginalForm(i.e.theFormdeployedviaWorkfloworsentastestusingtheDesigner).
Dynamicallyaddedwidgetsdon'tgetrestored.Torestoredynamicallyaddedwidgets,youhaveto:
l
Saveinformationthatrevealswhichwidgetswereaddeddynamically,andsavethevaluesof
theirinputfields.
Thiscodeshouldgointheeventhandlerfortheolcotgsavestateevent.
l
Add and initializethewidgetsagainaftertheFormisreopened.Makesuretoputanysavedval-
uesbackintheHTML.
Thiscodeshouldgointheeventhandlerfortheolcotgrestorestateevent.
l
Triggertherestore-state.cotgeventonthenewlyaddedwidget,tomakesurethatitisdis-
playedcorrectly.Forexample:
$('#myCamera").trigger('restore-state.cotg', event.detail.state);
Putthiscodeintheeventhandlerfortheolcotgrestorestate.event.
NotethatthewidgetmusthavethesameIDasbeforeinordertobeabletoretrieveitsstate.
Foradetailedexample,see:"SavingandrestoringCamerawidgets"below.
Example
Saving and restoring Camera widgets
ThisexampledemonstratesawaytosaveandrestoredynamicallyaddedCamerawidgets.Howtoadd
Camerawidgetsisexplainedinanothertopic:"DynamicallyaddingCOTGwidgets"onpage548.
WhenausertakesorselectsapicturewithaCamerawidget,theCOTGappstoresthepathtothe
imagethatwastakenorselectedinahiddeninput.Thisisthepathtotheimageonthedevicethatruns
theCOTGapp.OnsubmittingtheFormtheCOTGappreplacesthisvalue-thepath-withtheactual
imagedata.
InthisexamplethehiddenfieldsofdynamicallyaddedCameraelementshavegotthe.camera-dyn
Page 553