2022.1

Table Of Contents
Optionally, while initializing an element, you can make settings for this specific element. These
settings get prevalence over the options already specified in the HTML and over the default
settings specified in the COTG plugin.
The code snippet below initializes a new Camera element (with the ID myCamera) with a
number of settings:
$('#myCamera').cotgPhotoWidget({
quality: 50,
height: 1024,
width: 1024
});
The initialization functions and options of all widgets are listed in the Capture OnTheGo API:
"Capture OnTheGo API" on page652.
To learn how to set the defaults for one kind of elements, see "Changing default settings for
widgets" on page640.
Restoring a widget
When a Form is closed, the app stores the values of input fields to the local repository of the
app, but the values of input fields of dynamically added widgets are not stored.
When you reopen the Form the original input fields and their values are restored. However,
dynamically added widgets are not restored; this needs to be handled in code. How to do this is
explained in another topic: "Saving and restoring custom data and widgets" on the next page.
Example: adding Camera widgets dynamically
The following code inserts a Camera widget when the user clicks on a link or button with the ID
add-camera. The addCameraWidget() function creates and adds the widget. Each new widget
gets the class camera-dyn. The number of input elements that have this class is used to
construct a unique ID for each new Camera widget.
The HTML structure of the widget was copied from the Source tab after inserting a Camera
widget to a Form in the user interface of the Designer. The addCameraWidget() function
appends this HTML to a <div> with the ID cameras, which was already present in the form.
Subsequently the widget is initialized so that it is linked to the COTG app and the hardware
features of the device.
$(document).ready(function() {
$('#add-camera').on('click', function() {
var cameraID = "camera_" + getCameraIndex();
Page 644