← Back to team overview

dhis2-users team mailing list archive

Re: Scripting in Custom forms for Tracker Capture

 

Hi Sam,

Tracker and event capture apps are based on AngularJS, which works a little
differently from the standard jQuery way of accessing and modifying form
fields.

The steps below, will give you a general structure to interact with form
fields.

First access the custom form

var myForm = document.querySelector('d2-custom-form'); // in tracker custom
forms are under special tag <d2-custom-form />

Now this form contains all models that are exposed inside custom form. In
Angularjs models are defined as scope.

var $scope = angular.element(myForm).scope();

This gives you all scopes, but you need only those relevant to the custom
form input fields. If it is about data entry - the model is "currentEvent"
but if it is registration it is "selectedTei"

$scope.currentEvent - gives you access to data entry fields
$scope.selectedTei - gives you access to registration fields

To access values per data element or attribute, you just say

$scope.currentEvent[data_element_id] or
$scope.selectedTei[attribute_id]

If you want to change value just do

$scope.$apply(function(){
        $scope.currentEvent[data_element_id]= 'new_value';  // if you want
to change data element value
        $scope.currentEvent[attribute_id]= 'new_value;  // if you want to
change attribute value
});


Hope this gives you some direction. As Alex mentioned, you need to think
the AngularJS way :)

---
Thank you,
Abyot.

On Mon, Mar 21, 2016 at 12:32 PM, Sam Kasozi <kasozis@xxxxxxxxx> wrote:

> Hi Alex, Is there any reference like we have for the aggregates, detailing
> namespaces and the like?
>
>
> regards,
>
> Sam Kasozi
> +256 788-993-565
> Skype: sam.kasoziug
>
> On Mon, Mar 21, 2016 at 2:16 PM, Alex Tumwesigye <atumwesigye@xxxxxxxxx>
> wrote:
>
>> Dear Sam,
>>
>> The  custom forms are working well with my IDSR instance. I recently
>> upgraded from individual records to Tracker capture and everything works
>> well.
>>
>> You need to think 'AngularJS' not JQuery/JavaScript otherwise the
>> developers enabled it.
>>
>> Alex
>>
>> On Mon, Mar 21, 2016 at 1:36 PM, Sam Kasozi <kasozis@xxxxxxxxx> wrote:
>>
>>> Dear developers,
>>>
>>> JavaScript that used to work in the custom form with Individual Records
>>> fails to work in the Tracker capture. I have been wondering if the
>>> environment has been enabled for Tracker capture with different syntax
>>> convention as it is with the aggregate custom forms. And also whether there
>>> is documentation to refer too.
>>>
>>> http://dhis2.github.io/dhis2-docs/2.22/en/user/html/ch06s02.html#d5e1369
>>>
>>> regards,
>>>
>>> Sam Kasozi
>>> +256 788-993-565
>>> Skype: sam.kasoziug
>>>
>>> _______________________________________________
>>> Mailing list: https://launchpad.net/~dhis2-users
>>> Post to     : dhis2-users@xxxxxxxxxxxxxxxxxxx
>>> Unsubscribe : https://launchpad.net/~dhis2-users
>>> More help   : https://help.launchpad.net/ListHelp
>>>
>>>
>>
>>
>> --
>> Alex Tumwesigye
>>
>> Technical Advisor - DHIS2 (Consultant),
>> Ministry of Health/AFENET
>> Kampala
>> Uganda
>> +256 774149 775, + 256 759 800161
>> Skype ID: talexie
>>
>> IT Consultant (Servers, Networks and Security, Health Information Systems
>> - DHIS2, Disease Outbreak & Surveillance Systems) & Solar Consultant
>>
>>
>> "I don't want to be anything other than what I have been - one tree hill "
>>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dhis2-users
> Post to     : dhis2-users@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dhis2-users
> More help   : https://help.launchpad.net/ListHelp
>
>

Follow ups

References