Premature "This field is required" error when a previously hidden field is made mandatory by a program rule (Capture app)

Hi everyone,

I ran into a Capture app (web) issue a couple of months back and logged it in Jira. It hasn’t been picked up yet, so I wanted to raise it here to see whether others have hit the same thing and whether anyone has found a workaround.

When a data element (DE) field X is first hidden via program rule A, and then later made visible and mandatory via program rule B (once program rule A’s condition is no longer valid & program rule B’s condition for making the DE mandatory is valid), the web Capture app shows a “This field is required” error by default before any user interaction has taken place:

A few things worth highlighting:

  • The error still appears after setting rule A’s priority to 1 and rule B’s priority to 2.
  • It doesn’t happen if field X is never hidden and is only made mandatory by rule B. In that case the field behaves correctly and no premature error is shown.
  • It doesn’t happen in Android app.

To reproduce:

  1. Create a data element field X.
  2. Create program rule A that hides field X when a condition is met, e.g. a Yes/No data element “Has condition” with the expression #{hasCondition} == true.
  3. Create program rule B that makes field X mandatory, using the oppsosite condition: #{hasCondition} != true.
  4. In the Capture app (web), enter data so that rule A’s condition is true so that field X becomes hidden.
  5. Then change the data so that rule A’s condition is no longer true so that field X becomes visible again and rule B makes it mandatory.

I’d really appreciate it if anyone has found a workaround for this issue while we wait for it to be fixed.

Thanks!

Hi @malekpour

I need to ask this question: what if program rule is more specific so that it is not triggered until a certain value select? For example, instead of #{hasCondition} != true we can be specific by changing it to #{hasCondition == false.

However, while asking you this question, I feel that I missed something which would be clearer to me if we have the workflow.

Thanks!

Hi @Gassim,

Thanks for your reply. No, it’s not working by using more specific condition. Here is an example workflow:

Let’s assume that I have a YES/NO question as “Do you smoke?”. Then, only if the answer to this question is YES, I want to ask an additional mandatory question as “For how many years?”.

PR1: Hide “For how many years?” if “Do you smoke?” != YES
PR2: Mandate “For how many years?” if “Do you smoke?” == YES

The reason for PR2 is that it’s not possible to hide a compulsory DE; thus, we need to manually make it mandatory via a PR.

Thanks a lot!

Hi @malekpour

Thanks for the clarification. I tried to reproduce the issue on play. I have done the following by testing in “Child Programme”:

  1. Created two program rules:

And here’s a recording of the result:


The issue when I’m testing is that the part that’s not working is making it mandatory. Therefore, I tried creating a third program rule which checks if BCG Dose value and if it’s a Yes, it sets OPV as required:

The problem is that the result is exactly the opposite: when BCG is not “Yes” the actions are being triggered, see screenshot:
oppositeOfExpectation

I’m testing in web Capture app:
{
“app_name”: “Capture”,
“app_version”: “107.0.1”,
“global_shell_version”: “1.12.3”,
“dhis2_version”: “2.44-SNAPSHOT”,
“dhis2_revision”: “fccb7f9”
}

But I was able to reproduce the same exact thing in:
{
“app_name”: “Capture”,
“app_version”: “107.0.1”,
“global_shell_version”: “1.12.3”,
“dhis2_version”: “2.43.1”,
“dhis2_revision”: “9cbfbf3”
}

Here’s a complete metadata export for the Program Rules/Actions/Variables during testing:
ProgramRuleMetadataExport.json (126.9 KB)


I think these might be two bugs in the web Capture app (could you try to reproduce them as well?) in addition to the original issue you are facing. I will triage this to the @dhis2-tracker team (@tracker-programRules).

Thanks!