Ranking choices from a multiple select in a repeat loop (without duplicates)

Hi,

For a project I'm working on, I'm trying to design a form that allows me to rank options in an exhausting choice list. The process is as follows:

  • The user selects, let's say, n options from a list of N possible choices.
  • This will trigger a repeat loop that runs n times
  • In this repeat loop with n options, the user is asked to select their first choice, second choice etc.
  • Once an option has been selected in one repeat instance, it should not be possible to select it again in subsequent repeats

I have managed to get the desired behaviour in an XLSform. I can even call on the data after the repeat loop is closed further along in the form. However, when I proceed to submit the form somehow the data of the repeat loop is lost, leaving me with either a bunch of empty cells or even an error when the question in the repeat loop is required. Doe anybody know what I'm doing wrong?
I've attached an example to illustrate.

Thanks!

Martijn

test.xlsx (9.3 KB)

Hi Martijn,

I think what is happening is when you hit save the ODK is running the
validations which includes recalculating various elements. I suspect this
includes recalculating the choice_filter. When it does so it detects all
valid values have been entered for Q2 and eliminates them all from the
value list, leaving you with an empty value list (and eliminating the value
you had previously entered).

It is a bit of a "which came first the chicken or the egg" thing, but I
think it is basically going back and re-creating the value lists based on
the programmed criteria but the considering the values you just entered,
leaving you with no possible values (and so a question without a response).

I'm not sure this fix will work within the context of a choice_filter, but
what I've done in similar situations is limit it to only looking at
previous loops relative to the current loop (so it isn't looking forward
and considering ALL entered values).

Something like this:
selected(${Q1},lala) and not(selected(join(' ',/test/whatever[(n <
current()/n)]/Q2),lala))

It seems to work for me, but choice_filter can be picky so no promises. If
that doesn't work, I've also stored a list of all choices made outside the
repeat and checked against that for duplicates. With this you wouldn't
filter the choice list per repeat, you'd just validate the choices against
previous choices. Not quite as tidy but it might help if option a is
giving you problems.

Jason

ยทยทยท On Tuesday, March 21, 2017 at 2:06:44 PM UTC-4, martij...@hiil.org wrote: > > Hi, > > For a project I'm working on, I'm trying to design a form that allows me > to rank options in an exhausting choice list. The process is as follows: > - The user selects, let's say, n options from a list of N possible > choices. > - This will trigger a repeat loop that runs n times > - In this repeat loop with n options, the user is asked to select their > first choice, second choice etc. > - Once an option has been selected in one repeat instance, it should not > be possible to select it again in subsequent repeats > > I have managed to get the desired behaviour in an XLSform. I can even call > on the data after the repeat loop is closed further along in the form. > However, when I proceed to submit the form somehow the data of the repeat > loop is lost, leaving me with either a bunch of empty cells or even an > error when the question in the repeat loop is required. Doe anybody know > what I'm doing wrong? > I've attached an example to illustrate. > > Thanks! > > Martijn

Hi Jason,

Thanks for explaining it so clearly, it makes sense now. Your solution
seems to work perfectly in the test form and I'll try implementing it in my
main form on Monday.
Seriously, thank you so much. You've made my day :slight_smile:

Regards,
Martijn