Display Conditions Overview

Display conditions, sometimes also called skip logic,are used to determine when a particular question should be shown to a user. While you can use the Form Builder to make basic display conditions, it is also possible to create very complex expressions. This page demonstrates how to set up Display Logic in your CommCare application.

Table of Contents:

Display when there is or is not an answer in a question

  • To show a question when there is ANY answer to a previous question, use #form/previous_question != ''  (that is two single apostrophes: null).  As long as there is some answer input for previous_question, this returns true and your current question will display.

  • To show a question when there is NOT an answer to a previous question, use #form/previous_question = ''  (that is two single apostrophes: null).  This could be because previous_question was skipped, or because the user proceeded past previous_question without inputting an answer.

Display based on previous answers

To show a question if a previous question was answered "yes" this time OR last time.  This is common for things like Tetanus (TT) injections and Antenatal Care visits.  When the same form is used across multiple visits, you want to skip the first TT question and only ask about the 2nd tetanus if the beneficiary answered "yes" for TT1 at any time (this visit or any previous visit).  

  • Save the answers to TT1 and TT2 as case properties

  • Place logic on the TT1 question: #case/TT1 != 'yes'

  • Place logic on the TT2 question: (#case/TT1 = 'yes' or #form/TT1 = 'yes') and #case/TT2 != 'yes'

Display an answer to a previous question

You can display the output of any question by dragging the question you want to display from the Question Tree to the label of the question where you want it displayed. When you drag the question onto the label box in the Basic Question Properties you will see a green check mark indicating that you can release the cursor. We recommend using this drag-and-drop method to prevent spelling or formatting errors. The question you are referencing will be shown in the label box as <output value="..." />

If you drag a date question you will see several options for formatting when you drag the question:

  • No formatting (displays the date in the default date format)

  • DD/MM/YY (21/02/2012)

  • DDD, MMM DD, YYYY (Fri, Sep 12, 2014)

Example: This question is displaying the answer to "edd_calc" in the label. On the phone, <output value = "/data/edd_calc"/> will appear to the user as whatever edd_calc is defined as. For example "Her estimated date of delivers is 21/02/2012" or "Her estimated date of delivery is Fri, Sep 12, 2014" 

Screenshot 2024-04-19 at 10.07.51 PM.png

 Other notes about output expressions

  • It is also possible to manually compose an output expression. For example, to display the answer to the question with the ID mother_name, type the following in the display text of a question later in the form: <output value="/data/mother_name"/>

  • To display the answer to a question that is in a group, be sure to show the full path: <output value="/data/mother_questions/mother_name"/>

  • To manually format format the display of a date: <output value="format-date(/data/edd_calc, '%e/%n/%y')"/>

  • An output expression will not update automatically if it relies on a question (or on a hidden value that relies on a question) that appears on the same page/screen (if you are using a Question List) as the output expression. Bear this in mind when deciding where to place an output expression.

  • To show the "label text" (or "display text") of a choice instead of the choice value you can use the following syntax: <output value="jr:itext(concat('question-', /data/question,'-label'))"/>.

    • Note that this may not work if you have copied a question, because the itext ID may not match the question ID. For example, if you want to display the choice label for a question with the question ID site, in a group called intro (i.e. /data/intro/site) the expression would look like: <output value = "jr:itext(concat('intro/site-', /data/intro/site,'-label'))"/>.

    • This also may not work if you have several single select or multiple select questions that use the same set of options. When your application is built, questions that share choices are combined, to make the form smaller and faster. This means that if you reference a question that uses the exact same set of choices as another question, referencing that question's ID may cause an error.

 

For more guidance, see .

Displaying based on a range

You can also show a specific message when the answer to a question is within a specified range. For example, you might have different messages based upon the score from a test: (Good, Fair, Poor)

  • Create three different Labels, each of which will represent one of the outcomes (Good, Fair, Poor).

  • In the Display Condition, enter a value which will be True if the label should be displayed. We'll say that Good is greater than 75, Fair is between 75 and 50, and poor is below 50. The three display conditions would be:

    • Good: #form/score > 75

    • Fair: #form/score <= 75 and #form/score > 50

    • Poor: #form/score <= 50

Displaying based on a date

You can also write display logic for questions you want to appear at a certain time of year using format-date. For example, if you'd like a question to appear only in the month of August, you'd put format-date(date(today()), '%n') = 8 in the display condition. See .

Display the number of times a form has been filled out

You can do some creative work with hidden values to keep track of the number of times a given form has been completed by a specific user. Let's imagine you have a form that is used to take height and weight data every week, but every 10th week you also want to take some additional measurements. Or perhaps you want to show the number of times a form was filled out in the case details screen. Either way you will need hidden values structured like this example:

  • prev_visit_count

    • Calculate condition: (blank)

    • Do not save to the case

    • Loads the value of visit_count

  • visit_count

    • Calculate condition: if(#case/prev_visit_count = '', 1, #case/prev_visit_count +1)

    • Save to the case as: visit_count

    • Do not load anything into this hidden value

You can then display the value of visit_count or reference it in a display condition. 

Make a form disappear from a form list once it has been filled out, or make forms appear in sequence