2022.2

Table Of Contents
$(#myCamera).cotgPhotoWidget();
Optionally,whileinitializinganelement,youcanmakesettingsforthisspecificelement.Thesesettings
getprevalenceovertheoptionsalreadyspecifiedintheHTMLandoverthedefaultsettingsspecifiedin
theCOTGplugin.
ThecodesnippetbelowinitializesanewCameraelement(withtheIDmyCamera)withanumberofset-
tings:
$('#myCamera').cotgPhotoWidget({
quality: 50,
height: 1024,
width: 1024
});
TheinitializationfunctionsandoptionsofallwidgetsarelistedintheCaptureOnTheGoAPI:"Capture
OnTheGoAPI"onpage557.
Tolearnhowtosetthedefaultsforonekindofelements,see"Changingdefaultsettingsforwidgets"
onpage547.
Restoring a widget
WhenaFormisclosed,theappstoresthevaluesofinputfieldstothelocalrepositoryoftheapp,but
thevaluesofinputfieldsofdynamicallyaddedwidgetsarenotstored.
WhenyoureopentheFormtheoriginalinputfieldsandtheirvaluesarerestored.However,dynamically
addedwidgetsarenotrestored;thisneedstobehandledincode.Howtodothisisexplainedinanother
topic:"Savingandrestoringcustomdataandwidgets"onthenextpage.
Example:addingCamerawidgetsdynamically
ThefollowingcodeinsertsaCamerawidgetwhentheuserclicksonalinkorbuttonwiththeIDadd-
camera.TheaddCameraWidget()functioncreatesandaddsthewidget.Eachnewwidgetgetsthe
classcamera-dyn.ThenumberofinputelementsthathavethisclassisusedtoconstructauniqueID
foreachnewCamerawidget.
TheHTMLstructureofthewidgetwascopiedfromtheSourcetabafterinsertingaCamerawidgettoa
FormintheuserinterfaceoftheDesigner.TheaddCameraWidget()functionappendsthisHTMLtoa
<div>withtheIDcameras,whichwasalreadypresentintheform.Subsequentlythewidgetisinitialized
sothatitislinkedtotheCOTGappandthehardwarefeaturesofthedevice.
$(document).ready(function() {
$('#add-camera').on('click', function() {
var cameraID = "camera_" + getCameraIndex();
addCameraWidget(cameraID);
});
Page 550