Scripting in Custom forms for Tracker Capture

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

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@gmail.com 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@lists.launchpad.net

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 "

Hi Alex, Is there any reference like we have for the aggregates, detailing namespaces and the like?

regards,

···

On Mon, Mar 21, 2016 at 2:16 PM, Alex Tumwesigye atumwesigye@gmail.com 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

Sam Kasozi
+256 788-993-565

Skype: sam.kasoziug

On Mon, Mar 21, 2016 at 1:36 PM, Sam Kasozi kasozis@gmail.com 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@lists.launchpad.net

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 "

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

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 :slight_smile:

On Mon, Mar 21, 2016 at 12:32 PM, Sam Kasozi kasozis@gmail.com wrote:

Hi Alex, Is there any reference like we have for the aggregates, detailing namespaces and the like?

regards,


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp


Thank you,
Abyot.

Sam Kasozi
+256 788-993-565

Skype: sam.kasoziug

On Mon, Mar 21, 2016 at 2:16 PM, Alex Tumwesigye atumwesigye@gmail.com 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@gmail.com 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@lists.launchpad.net

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 "

Hi Abyot,

Yes it does give some direction on how to alter the customization.

Thank you all.

···

On Mon, Mar 21, 2016 at 2:41 PM, Abyot Asalefew Gizaw abyot@dhis2.org wrote:

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

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

});

Sam Kasozi
+256 788-993-565

Skype: sam.kasoziug

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


Thank you,
Abyot.

On Mon, Mar 21, 2016 at 12:32 PM, Sam Kasozi kasozis@gmail.com wrote:

Hi Alex, Is there any reference like we have for the aggregates, detailing namespaces and the like?

regards,


Mailing list: https://launchpad.net/~dhis2-users

Post to : dhis2-users@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-users

More help : https://help.launchpad.net/ListHelp

Sam Kasozi
+256 788-993-565

Skype: sam.kasoziug

On Mon, Mar 21, 2016 at 2:16 PM, Alex Tumwesigye atumwesigye@gmail.com 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@gmail.com 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@lists.launchpad.net

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 "