Hello All,
This is Adeeb from Bangladesh. My team and I are conducting a baseline
survey. We are using xlsforms to build the digital questionnaire and have
found this group and the resources available in the ODK website quite
invaluable.
We are currently tweaking and testing the form on ODK collect and by and
large everything is running very smoothly. One of the things we are trying
to do is build in as many validation checks as possible. We have a large
number of select_multiple questions with an equally large number of
options; the structure of the options available makes validation some times
tricky.
We were struggling with logic for the constraints (i.e. the validation
checks) for a while but feel that we've hit on a shortcut; however I was
still wondering if there was an easier way to do it;
To explain; for example; one of the questions asks
"Have any of your household members received the following training?"
(hh_training) and presents the following choices:
hhtraining_agri
Agriculture related
hhtraining_ipm
IPM, ICM or IFM
hhtraining_fish
Fish culture
hhtraining_live
Cattle and poultry rearing
hhtraining_handi
Handicraft and cottage industry
hhtraining_tech
Technical
hhtraining_busdev
Business development
hhtraining_promgt
Project management
hhtraining_oml
Organizational management and leadership training
hhtraining_mobs
Bookeeping/Accounts keeping
hhtraining_none
Not taken any training
hhtraining_other
Other
Now initially we had one more choice, "Don't know" but setting up the logic
for that proved to be just too tricky and we just caved and changed the
question a little bit to include the "don't know" option in the "other"
option's text prompt.
The constraint we applied is: "not(selected(.,'hhtraining_none') and
(selected(.,'hhtraining_agri') or selected(.,'hhtraining_other') or
selected(.,'hhtraining_ipm') or selected(.,'hhtraining_fish') or
selected(.,'hhtraining_live') or selected(.,'hhtraining_handi') or
selected(.,'hhtraining_tech') or selected(.,'hhtraining_busdev') or
selected(.,'hhtraining_promgt') or selected(.,'hhtraining_oml') or
selected(.,'hhtraining_mobs')))" which is painful even to read.
Essentially this is a validation check where the enumerator cannot select
both a "No training" and any other option at the same time.
The problem was that we had a large number of questions which were
select_multiple but where the selection of one particular option
invalidates the others, i.e. in the context of the question you cannot have
someone who received "agricultural training" as well as answering "i have
not taken any training".
So as not to rewrite this lengthy bit each time for different questions, we
devised a shortcut. What we've started using instead (and have tested it
and found it works perfectly...so far) is this constraint instead
"not(selected(., 'hhtraining_none') and count-selected(.) >=2)" which
basically reads "if hhtraining_none is selected and the number of options
selected is 2 or more, then: false" and error message.
This is working for us, but I was wondering if there was an easier way?