These operators cause the specified question, question range or section to appear or disappear if the check or condition is true. When you use .appear or .disappear, you force the specified questions to take on the opposite state by default: for example, anything that you put in an .appear, will normally not be shown, and will only show if the condition that you check is true. Some examples of how .appear and .disappear can be used:
.appear(Q(20)) // show question 20 .disappear(QRange(30, 120)) // hide questions 30 through 120 .appear(Section(3)) // show section 3
Appear and Disappear conflicts
Situation: you have multiple rules that either appear or disappear a question.
(Questions 21 and 31 are Yes/No questions. Questions 101 and 111 are Narratives.)
ifQ(21) .answered(1) .disappear(Q(101));
ifQ(31) .answered(1) .disappear(Q(101),Q(111));
// the above rules will not work properly
The logic of this rule is: if question 21 is answered Yes (1), disappear question 101, and if question 31 is answered Yes, disappear questions 101 and 111. Although RuleZ can implement this logic, the rules as written above will not work properly. The reason for this is due to how the appear and disappear rules function.
Disappear and appear are compound actions, in that they will act differently depending on whether the condition is met. Consider the appear rule:
ifQ(31) .answered(2) .appear(Q(131));
The logic is: if question 31 is answered No (2), appear question 131. However, that's not all. There is a second, implied rule, that is: if question 31 is NOT answered No (2), disappear question 131. The affect of this is clear – when you choose the answer to a question that triggers an appear or disappear, choosing a different option will cause the opposite effect.
This brings us back to why our original situation was not working. Consider this rule set again:
ifQ(21) .answered(1) .disappear(Q(101)); ifQ(31) .answered(1) .disappear(Q(101),Q(111));
// the above rules will not work properly
Let's say you are filling the shop, and you fill in question 21 with a Yes (1), and fill in question 31 with a No (2). How should the rule function. Logically, you would like question 101 to disappear. But what is really happening? Let's look at it rule by rule.
According to the first rule, question 101 should disappear because of how we answered question 21.
According to the second rule, question 101 should not disappear because of how we answered question 31. However, as we discussed above, this triggers the implied rule, which in this situation is "if question 31 is not answered Yes, appear questions 101 and 111".
Clearly there is a conflict. Because RuleZ processes your rules one at a time from top-to-bottom, the last state rule affecting a question will be experienced. In this case, for question 101, it is to appear.
Solution
The solution to this situation is simple, but requires some lateral thinking. Here it is:
ifQ(21) .answered(1) .orQ(31) .answered(1) .disappear(Q(101)); ifQ(31) .answered(1) .disappear(Q(111));
You'll notice that logically, this rule does the same exact thing as the original rules: if question 21 is answered Yes or question 31 is answered Yes, disappear question 101, and if question 31 is answered Yes, disappear question 111. The conditions may be regrouped, but the logic is the same.
However, these rules will run differently, and in fact they will work as expected. This is because there is only one place where question 101 is being called to disappear. This means that you do not have to worry about another rule (or implied rule) conflicting the appearance or disappearance of question 101.
It is important to always group your conditions in this way to avoid conflicts.
Examples:
ifQ(31) .answered(2) .appear(Section(22)); // section is initially hidden until rule is true // can also use one or more other selections // .appear(Q(11), Q(21)) // .appear(QRange(100,400), QOrder(1000,1200))