Some answers are wrong in a way the question can tell. A date of birth after the interview, a phone number one digit short, shares of a household budget that do not add up: each can be refused while the respondent is still there to fix it.
Give a question a rule
- In the Survey Builder, select the question.
- Under What this question accepts, write the rule in Rule, written as an expression. Write
.for this question's answer, for example. >= 18 and . <= 120, or. < today()for a date. - Write what the respondent reads when an answer breaks it, in Message when an answer breaks the rule.
A rule can read earlier answers too. For example, . <= ${household_size} keeps a count within the household. It can match a pattern with regex(), for example regex(., '^07[0-9]{8}$') for a Kenyan mobile number. The builder says at once if the rule cannot be read, or if it reads a question asked after this one.
The message is translated with the rest of the question, so a Kiswahili respondent reads it in Kiswahili once the translation is reviewed. Without a message, the platform's own sentence is shown.
Require an answer only sometimes
Leave Must be answered off, then set Must be answered only when. Choose an earlier question and an answer from the lists, or choose Write it as an expression, for example ${age} >= 18. The question shows Required when… in the list.
Where it is checked
Everywhere an interview is answered. The web link checks each answer, online and with no connection, and so do the interviewer app and staff data entry. The server checks every answer again when the interview arrives, with the same rules and on the interview's own date. A rule is read the same way in each, so one channel cannot accept what another refuses.
From an XLSForm
A constraint imports as written. With a constraint_message, the message comes too, and so do its translations in constraint_message:: columns. A required cell holding a condition, such as ${consent} = 'yes', becomes Must be answered only when.
A constraint or a required condition that reads a question asked after it is listed with its row number and left out. Here a question is checked as it is answered, so a later answer cannot be read in time.