It’s possible to display answers from open questions later on in the module as text, e.g., asking for a goal XY and after some pages ask clients how their goal XY is going.


To do this:

  1. turn on the “use in computation” toggle
  2. give a name to the question
  3. write a short code in the computation like this:

reference: function (data) {

  return data.name_of_open_question;

}

  1. to get the text back later on in the module use ${computation:reference} in the module.
  2. done. The answer of the open question should be displayed in the module now as text.
If you want to reference an answer from another chapter, it might be that the therapist has turned it off. Then there will be no answer to display. For these cases you can use the following code:

food_reference: function(data) {

        var food = data.food;

        if (typeof food === 'string') {

            return food;

        } else return "The question has not been answered.";

    }


This code checks if the value from the open question is a string (text). If yes, the open question was answered and the answer can be displayed. If not, the function gives back something else, here: “The question has not been answered.”


The same applies to referencing answers from a multiple choice / single choice question:

// Single choice

fruit_answer: function(data) {

      if (typeof data.fruit === 'number') {

        if (data.fruit === 90) {

            return "Apple";

        } else if (data.fruit === 91) {

            return "Banana";

      } else return "This question was not answered";

  }

// Multiple choice

animals: function(data) {

  if (typeof data.animal === 'object') {

      var animal = [];

      if (data.animal.includes(1)) {

          animal.push("Cat");

      }

      if (data.animal.includes(2)) {

          animal.push("Dog");

      }

      return animal.join(", ");

  } else return "this question was not answered";