Using a choice for two different options with choice filter?

The answer to this question is probably simple but I can't figure out how to make it work.

Suppose my survey page looks like this:
name label choice_filter

photo_type Photograph Type
photo_dir Photograph Description photo_type=${photo_type}

And my choices page looks like this:
list_name name photo_type

photo_type_list landscape
photo_type_list closeup

photo_dir_list up
photo_dir_list down
photo_dir_list center
photo_dir_list other

If I wanted BOTH landscape and closeup photos to have the option to chose "other", how would I set up the choice filter?

I've tried putting 'landscape' or 'closeup'.
I've tried putting 'landscape' 'closeup'
I've tried putting 'landscape', 'closeup'
I've tried putting selected(${photo_type}, 'landscape') or selected(${photo_type}, 'closeup')

Nothing. I am stumped. Ideas?

Attaching this simplified xls file you've based this off of would help.

Attached is a form with an example of a choice filter.
If memory serves, this form is broken w.r.t. the repeat functionality.

But it shows how you can use a choice_filter

choice.xls (22.5 KB)

··· On Fri, Apr 3, 2015 at 7:06 PM, wrote:

The answer to this question is probably simple but I can't figure out how
to make it work.

Suppose my survey page looks like this:
name label choice_filter

photo_type Photograph Type
photo_dir Photograph Description photo_type=${photo_type}

And my choices page looks like this:
list_name name photo_type

photo_type_list landscape
photo_type_list closeup

photo_dir_list up
photo_dir_list down
photo_dir_list center
photo_dir_list other

If I wanted BOTH landscape and closeup photos to have the option to chose
"other", how would I set up the choice filter?

I've tried putting 'landscape' or 'closeup'.
I've tried putting 'landscape' 'closeup'
I've tried putting 'landscape', 'closeup'
I've tried putting selected(${photo_type}, 'landscape') or
selected(${photo_type}, 'closeup')

Nothing. I am stumped. Ideas?

--

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

Hi Mitch,

The example I gave was a hypothetical, I've attached a trimmed down version of the actual form I am using. I tried to model mine after the example you gave but it still does not work....

Slimmed.xlsx (16.3 KB)

Also note that I didn't even try to have any choices be offered for multiple answers in this sheet. My main focus was just trying to get the repeat to recognize the unique answers for each repeat but now I can't select any choices.

Simplified examples are easier to fix, and then you can work on building
them out.

I've changed your choices sheet to have a column heading of
'feature_cat_filter' so that it is clearer what is going on.

Attached is a working implementation.

When you are working inside repeat groups, things get tricky.

In your example, you don't need to use indexed-repeat() because you are
referencing a value within your current repeat group. So you can use
relative addressing, e.g.,

../../g3/feature_cat

from within the feature_type field (instead of ${feature_cat})

../ gets up to the g4 group
../../ gets up to the parent of the g4 group (r1)
../../g3 navigates into the g3 group
../../g3/feature_cat references the value of the feature_cat field for
this iteration of the group.

i.e., relative addressing is a central concept to use and understand when
working within repeat groups.

HOWEVER, there is a gotcha in the evaluation logic whereby the filter
criteria
is evaluating one level up (starting at g4 instead of at
'feature_type'). I believe this is a bug, but it has been out there so
long, we can't really fix it. So when we reference the feature_cat within
the filter criteria, we need to drop a leading ../ (using
../g3/feature_cat).

This is different than if you had tried to use relative referencing
within relevant, calculate or constraint conditions. In those, you would
need to write ../../g3/feature_cat

BUT, it still doesn't work.

The filter condition translates into the XML representation:

        <itemset

nodeset="instance('feature_type_list')/root/item[feature_cat_filter
=../g3/feature_cat]">


And that is incorrect XML. The filter condition:

 [feature_cat_filter =../g3/feature_cat]

evaluates all relative (..) addressing relative to:

instance('feature_type_ist')/root/item

i.e., ../g3/feature_cat is evaluated within the choices list, and not
within the form submission we are capturing. The solultion is to add
current()/ in front to reference to evaluate it within the current form
submission. That gives:

        <itemset

nodeset="instance('feature_type_list')/root/item[feature_cat_filter
=current()/../g3/feature_cat]">


which works.

Again, the corrected form is attached.

Enjoy!

Slimmed.xlsx (16.2 KB)

··· On Mon, Apr 6, 2015 at 4:59 PM, wrote:

Also note that this one hasn't even been altered to allow shared choices
for different answers. If I use this form in ODK collect, the option to
select any choice disappears.

--

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

First and foremost, my infinite thanks to you. Not sure if you get your due respects for doing this kind of help but you certainly deserve it.

It looks like my very first attempt (not the one I attached!) at getting this to work was right except that I didn't have they key bit of information about specifying the group.

So now to return to my original question - how can I make a choice filter that will allow a common response for two different question? I assumed a calculate function would be necessary but even then I couldn't get it to work. Please see attached.

Slimmed.xlsx (12.8 KB)

For your current form, you are defining a calculation that will produce 3
values, 'distant', 'both' and 'close'. I believe the only thing missing is
that you need to quote those values (otherwise they are interpreted as
field names).

The filter condition column on the choices sheet would then have values
matching those ( distant, both, close ) and the choice_filter column would
be:

filter = current()/./photo_calc

The leading ./ (or ../g25) is needed because current()/field would be
interpreted as an absolute path (like a current()/${field} expansion).

Alternatively, keep in mind that you can have any number of filter columns
on your choices sheet (that is how cascading selects work).

So in some cases, it may be easier to have several calculated fields, e.g.,

satisfy_close_filter
satisfy_distant_filter

and then have a more complex filter expression using 2 or more columns.

i.e., you might have filter columns on the choices sheet:

for_close_shots
for_distant_shots

And then your filter condition would be:

for_close_shots = current()/./satisfy_close_filter or
for_distant_shots = current()/./satisfy_distant_filter

This doesn't work well in your particular example, but it might work nicely
for more complex filtering conditions across multiple independent factors
(e.g., combinations of ethnicity and age or earnings and ethnicity, etc.).

··· On Mon, Apr 6, 2015 at 7:07 PM, wrote:

First and foremost, my infinite thanks to you. Not sure if you get your
due respects for doing this kind of help but you certainly deserve it.

It looks like my very first attempt (not the one I attached!) at getting
this to work was right except that I didn't have they key bit of
information about specifying the group.

So now to return to my original question - how can I make a choice filter
that will allow a common response for two different question? I assumed a
calculate function would be necessary but even then I couldn't get it to
work. Please see attached.

--

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

sigh

I am just not good at this. The attached form is a bit of a mess right now because I wasn't able to get it to work and then I started cutting things out of the choice filter to get to the root of the problem.

Originally I was going to have three calculations, one for each of the three filter columns, each for a particular value in a choice list. Within each calculation, there would be a series of if statements that would result in the value I wanted for my choice filter if true and a garbage value if false.

The choice filter when then look at each calculation result, with only one of the calculations producing a value that could be found on one of my filter columns. After much frustration, I decided the problem must lie in the values the calculations were returning. So I stuck in a text field that would be labeled as whatever value the calculation came up with. The results were annoying.

If the calculation uses an absolute path like so:
if(${photo_type} = 'project_overview', 'far', 'negative')

The calculation produces the desired value (far).

If the calculation uses a relative path like so:

if(current()/../g3/photo_type = 'project_overview', 'far', 'negative')

The damn thing evaluates as false and gives me the garbage value (negative).

I've attached both, maybe you can figure it out....

Absolute.xlsx (17.6 KB)

Relative.xlsx (17.5 KB)