I hope this email finds you well, I have created custom forms and take value of input through javascript as below not working. one td input as below
let or var startdate=document.getElementById(“SgMeYGYp3w6-cKrBWrq5beU-val”).value;
console.log(startdate) I also convert toString() method but not working.
Please let me know how to take the values ? because I want to compare dates.
With Best Regards
Mohammad Ayub Yousafzai
Kabul , Afghanistan
Hi did you set the id manually? If it is not set manually it might be set by a script and if the script is changing the id each time the app loads the dataset then this code will not work. Either set the id yourself or use class and selectors.
As @Gassim highlighted, for the custom form to open, a script has to be executed to populate elements in the DOM. Assuming the ID you are referencing is expected in the form after it is ready, in order for your code to work, it has to be run after the custom form has finished rendering.
There are some event hooks that can help you determine if the form is ready, but I am not sure if they are still supported in latest version
Then the class name would be class=“printForm”; are you using a custom form? If so then from Maintenance → Dataset → select the dataset options and you will find the option to design it and from the designer you can customize the custom form. Where are you inserting the Javascript code you used above?
Hello @mohammadayub864
Have you tried to put your code within the following block? If not, then go for it provided dhis2 is supported.
dhis2.util.on('dhis2.de.event.dataValuesLoaded', function () {
// any codes like getElementById("id") or $("#id")...., api to datastore or analystics or any API can go here
// const orgUnitId = dhis2.de.currentOrganisationUnitId;
//const dimensions = dhis2.de.api.getSelections();
// EXAMPLE:
$('input[name ="entryfield"]').each(function (i) {
$(this).change(function () {
//codes for on changes on input fields
});
});
});
For the Expiry of Annual Fees Date column, add to each row in the code the class “check” which you will use in your JavaScript code to loop over each field and the one that has an expired date, you can add a class “highlight.” In the CSS , you can customize the “highlight” class to change the background color of all the input fields that were checked and added to “highlight” class.
Fort the script code, it can be added after the end of your data entry form code under the tag ; whereas, for the CSS [your-css] should probably be added to the top of the code. I can mark the location in the screenshot below: