Program Stage Custom Form Change Input Value

Dears,

Were working on different ways to utilize integration methods with different systems and currently I have problem using the custom form in the program stage where we need to change the input value from JavaScript code to build on a simple connection call through API to get, for example a Lab result from another system and store/change input value with coming data.

As a concept, we were able to use the following code example using custom form in the program form but it did not work on the program stage form. I tried to change the input value using angular and it worked using this code:

<p><button ng-click="currentEvent.jm9OF9FVMYp=currentEvent.jm9OF9FVMYp+1">update White blood cells Angular</button></p>

How do we get to access to this input id (currentEvent.jm9OF9FVMYp) from JavaScript code to get data from API then change input field value (Maybe using Angular inside JavaScript or JavaScript code access to Angular input values)?

so I create this JavaScript code below, but with this code we can change input value without change hidden value as you will see in screenshot

<p><button onclick="updateLabRed()">update red cell count JavaScript</button></p>
<script>
var x = 12;
function updateLabRed() {
    x++;
    applyChangeRedCell(x);
}
function applyChangeRedCell(value) {
    let nodes = document.querySelectorAll('[id="Hx0Y0dlPELF-viVD2imM6u6-val"]');
    if(nodes && nodes.length) {
        nodes.forEach(item => {
console.log(item);
            item.value = value;
        });
    }
}
applyChangeRedCell(x);
</script>

Using JavaScript
A1:


A2:

A3:

Using Angular
B1:


B2:

B3:

B4:

ng)

Hi

I’m not sure I follow the purpose of getting access to this input id? Why don’t you get the value directly from the API where ever this input field is saving the info to? As for changing the input you can use program rules.

2 Likes

Thanks @Gassim can you give me an example about using API with program rule ?

1 Like

So for example you want the user to input a value into the form and this value will be sent to another system? Why not assign the value to a data element and then request it using the API? Sorry @SalehAbbas, I just need to understand why are you trying to get the value from the input field rather than the metadata object?

Thank you!

1 Like

Thanks Again @Gassim ,

I try to get patient personal information from government system like (Ministry of Interior) just when user fill patient id and press a button then get all patient data and fill it on form input.

another example:
I need get all patient lab result from lab and store it on a patient stage same before using button to get all data and fill it on form input filed.

this allow to us to help users to use DHIS2 in quick way without build 3-party system, just inside custom form in DHIS2 and make DHIS2 powerful in connecting with other system.

I suggest this ticket below for DHIS2 team but still no answer

I understand your situation @SalehAbbas!

It is possible to create a custom dhis2 app which would perform the API request when the user clicks on the button; however, I don’t understand why do you need the user to click the button to fill in data that already exists as it is possible to send API requests to create/update/delete these values?

I really advice you to build upon a custom dhis2 app instead. (:

1 Like