Javascript usage for dataset?

hello everyone. Can local dhis2 take javascript for the dataset?

Hi @Roel

Welcome to the community and thanks for the question!

Yes, it’s possible to customize the form, but it has some disadvantages such as not being able to display the form exactly the same in the android app and not using basic HTML might cause issues with error reporting.

Custom Forms

When the form you want to design is too complicated for the default or section forms then your last option is to use a custom form. This takes more time, but gives you full flexibility in terms of the design. In DHIS2 there is a built in HTML editor (CK Editor) in the form designer which allows you to either design the form in the GUI or paste in your html directly (using the “source” window in the editor).
source

Here’s a recent demonstration from another post:

Hope this answers your question @Roel? Thanks!

Thanks for everything.

1 Like

I tried this code in the console and it works well. but if i do in the editor does not work
please.!!

1 Like

Please know that command in the console is only to illustrate the point; however, a developer famaliar with Java Script would need to customize the code based on the dataset form and need.

One reason why the code works in the console and not in the editor is because it needs to be included inside the script tag as well as used through a function. Additionally, it is using a random ‘selector,’ but to be used on a real form, id or class need to be used for proper selection.

Thanks!

Hi @Roel,

You can try with

<--script type="text/javascript">

dhis2.util.on( 'dhis2.de.event.formReady', function( event, datasetID) { 

----------------Your JS code here.....................

});
function myCustomFunction(parameter){

alert(parameter);

}
<-/script>

You can define and call any events from your input fields: 

<--input id="VsS1R8DztGn-dCWAvZ8hcrs-val" onkeyup="myCustomFunction('#VsS1R8DztGn-dCWAvZ8hcrs-val')" title="...." value=" .... " />

You can take a look at this example: https://dhis2trainingland.com/eportal/?tutorial=how-to-calculate-previous-month-value-in-dhis2-data-entry-form 

If you need any clarifications, don’t hesitate to let me know.

Thank you