Constraints on multiple select questions: is there an easier way?

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?

Your eventual constraint "not(selected(., 'hhtraining_none') and
count-selected(.) >=2)"
is the optimal one.

ยทยทยท On Thu, Mar 20, 2014 at 10:20 AM, Adeeb Choudhury <adeeb.choudhury@gmail.com wrote:

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?

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Is there a way of doing this when there are two items that cannot be selected together.
Eg. If Q1 has following multiple choice,
1.Use machine
2.Take risks
3.Set goals
4.Take initiative
5.Work with farmers
99.Other specify
0.None
98.Dont know

In this case how can I make 0 or 98 single select?

Thanks in advance

Is there a way of doing this when there are two items that cannot be selected together.
Eg. If Q1 has following multiple choice,
1.Use machine
2.Take risks
3.Set goals
4.Take initiative
5.Work with farmers
99.Other specify
0.None
98.Dont know

In this case how can I make 0 or 98 single select?

Thanks in advance

I got the solution. All is well now.
Thanks

ยทยทยท On 1 May 2016 19:20, "Louis Omoya" wrote:

Is there a way of doing this when there are two items that cannot be
selected together.
Eg. If Q1 has following multiple choice,
1.Use machine
2.Take risks
3.Set goals
4.Take initiative
5.Work with farmers
99.Other specify
0.None
98.Dont know

In this case how can I make 0 or 98 single select?

Thanks in advance

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to a topic in the
Google Groups "ODK Community" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/opendatakit/wfi11yGjYKg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I Louis can you tell us how you managed to set the condition.

ยทยทยท On Sunday, May 1, 2016 at 10:40:04 PM UTC+5, Louis Omoya wrote: > I got the solution. All is well now. > > Thanks > > On 1 May 2016 19:20, "Louis Omoya" wrote: > Is there a way of doing this when there are two items that cannot be selected together. > > Eg. If Q1 has following multiple choice, > > 1.Use machine > > 2.Take risks > > 3.Set goals > > 4.Take initiative > > 5.Work with farmers > > 99.Other specify > > 0.None > > 98.Dont know > > > > In this case how can I make 0 or 98 single select? > > > > Thanks in advance > > > > -- > > -- > > Post: opend...@googlegroups.com > > Unsubscribe: opendatakit...@googlegroups.com > > Options: http://groups.google.com/group/opendatakit?hl=en > > > > --- > > You received this message because you are subscribed to a topic in the Google Groups "ODK Community" group. > > To unsubscribe from this topic, visit https://groups.google.com/d/topic/opendatakit/wfi11yGjYKg/unsubscribe. > > To unsubscribe from this group and all its topics, send an email to opendatakit...@googlegroups.com. > > For more options, visit https://groups.google.com/d/optout.

In the case of Louis, the solution that works is the following:

"not((selected(., '0') or selected(., '98')) and count-selected(.) >=2)"

2 Likes