2022.2

Table Of Contents
Examples
Thesamplebelowattachesaneventhandlertothe"set"eventofaSignatureelement.Oncethesig-
natureisset(thatis,aftertheuserhasclickedtheDonebutton),theeventhandlertriggerseventsof
theDateandGeolocationelements.TheDateelementissetwithtoday'sdateandtheGeolocationele-
mentisupdatedwiththecurrentlocation.
$(document).ready(function() {
$('#signature').on("set.cotg", function() {
$("#date").trigger("set.cotg", new Date()); // set current date
$("#geolocation").trigger("update.cotg"); // get current geolocation
});
});
ThefollowingexampleinvokestheDatedialogwhentheuserclicksabutton.
$(document).ready(function() {
$('#my-datepicker-button').on('click', function() {
$('#date1').trigger("show-date-picker.cotg", new Date("2018-01-01"));
});
});
Dynamically adding COTG widgets
CaptureOnTheGo(COTG)widgetscanbeaddedtoaFormdynamically,viajQuery.Forexample:a
newCameraelementcouldbeaddedwhentheuserclicksanAddbutton.Thistopicexplainshowto
implementthis.ItisassumedthatyouhaveabasicunderstandingofHTMLforms,CSS,JavaScript,
andjQuery.
Prerequisites
Beforeyoucanstartwritingcodethataddsawidgetinresponsetoanactionoftheuser,youneedthe
following:
l
SomeelementontheFormtotriggerthecreationofthewidget.Thiscouldbeanythingthat
respondstoanactionoftheuser;abuttonorlink,forexample.Makesurethatthiselementhas
anID.
l
AFormelementtowhichthenewwidgetcanbeadded;a<div>forexample.Again,makesureto
givethiselementanID.
l
TheHTMLstructureandattributesofthewidget,sothatyoucanrecreateitincode.TheHTML
structureofawidgetcanbeseenontheSourcetabafterinsertingthesamekindofwidgetintoa
FormintheDesigner.
Also,ifyoudon'thaveaJavaScriptfileforyourcodeyet,addonetotheresourcesofyourtemplate
(see"AddingJavaScriptfilestotheResources"onpage513)andmakesuretoincludethatfileinthe
WebcontextorintheWebsectionthatcontainstheCOTGForm(see"IncludingaJavaScriptfileina
Webcontext"onpage515).
Page 548