Restrict choices already selected from a repeat group

buenas tardes, quisiera saber si puedo o minimizar un grupo de repetición a la hora de ingresar las respuestas en la encuesta. osea ocultar las respuestas que ya he ingresado, para ingresar las otras.

Welcome to the community, @miguel! Maybe you could try this out as outlined in the image below:

In the survey tab of your xlsform:

In the choices tab of your xlsform:

Image 2

Data entry screen as seen in Enketo:

Reference xlsform:

Restrict choices already selected from a repeat group.xlsx (11.2 KB)

1 Like

muchas gracias, es lo que buscaba

1 Like

Dear @Kal_Lam ,
your solution looks good but it does not work on Android with Kobocollect. When filling in more than two choices, and trying to end and save the form, you get the error from the screenshot attached. Would you know how to fix this? Thanks!

EDIT: Actually does not allow to validate forms also from the preview in kobotoolbox. (To replicate this error try adding at least three answers)

I need to restrict choices already selected from a repeat group exactly as described here: Restrict choices already selected from a repeat group
and here: Preventing duplicate entries in a repeat loop

The two solutions given are good but do not work on Kobocollect and Enketo when trying to add more than 2 instances of the repeat group. If you add 3 instances of the repeat group and try to send the form it throws an error. The error comes from the constraint being checked twice (once when the values are entered and once when the form has to be sent). The first time the constraint is met while the second time is not. How do I overcome this problem?

Thank you very much for your help.

Description

I need to restrict choices already selected from a repeat group exactly as described here: Restrict choices already selected from a repeat group
and here: Preventing duplicate entries in a repeat loop

The two solutions given are good but do not work on Kobocollect and Enketo when trying to add more than 2 instances of the repeat group. If you add 3 instances of the repeat group and try to send the form it throws an error.

Steps to Reproduce

  1. Download Restrict choices already selected from a repeat group.xlsx and upload it in a new project
  2. Preview the form with Enketo or deploy it and use it with Kobocollect
  3. Add at least 3 instances and try to validate data or save it on Kobocollect to see the error.

Expected behavior

The expected behaviour would be to prevent the user to repeat one-select answers in repeat groups.

Actual behavior

The control on duplicates works fine while filling the form but it does not let me finish the form because of an error thrown.

Additional details

*Your environment, why you think this might be happening.

I think that the error comes from the constraint being checked twice (once when the values are entered and once when the form has to be sent). The first time the constraint is met while the second time is not. How do I overcome this problem? Is this a bug?

Thanks!

@andrea_ageon, I just checked this at my end and it works perfectly as expected both in Enketo and Collect android app. The main objective of this workaround is to restrict the same entry twice in a repeat group. Please check XLSForm I shared here:

Dear @Kal_Lam,
have you tried to add more than 2 repeat groups? If you try to add at least three groups (for example selecting once “One”, once “Two”, once “Three”) you should be able to replicate the error. Thanks!

OK, I got it. So when you are with Enketo, and you have a repeat group of more than 3, the issue starts popping up. Similarly, when you are Collect android app and you have a repeat group of more than 4, the issue starts popping up.

Please note that this is not a system bug. It’s the limitation of the syntax. Maybe the community could help build from this point to overcome the limitation.

Thank you once again for flagging this in the community.

I have tried applying the same concept in my form but if I change the response it does not take off the error message. In the below image, I tried selecting visit 3A and then when the error message showed up, I changed the option to Visit 3B, However, the error message does not disappear.

Can you please have a look at the form and let me know how to rectify this.

ChemotherapyForm.xls (147 KB)

Appreciate any help.

Regards,

Hi @an_ju,

Have you considered using a choice filter rather than constraints? Here’s something that might work for your situation:

survey

type name label calculation choice_filter
calculate c1 concat(${visit})
begin_repeat visits Visits
calculate c2 substr(${c1}, 0, position(…) - 1)
select_one visits visit Visit not(contains(${c2}, name))
end_repeat

choices

list_name name label
visits 0 Visit 3A
visits 1 Visit 3B
visits 2 Visit 3C

choice-filter-repeat-group.xlsx (6.0 KB)

3 Likes

Hey Josh,

Sorry for the late response… And thank you for this view. I did not try this. Appreciate it very much.

sir what i had wanted was that if the option ‘One’ is selected, it should not show in subsequent repeats
e.g in first repeat if “One” is selected, second repeat should only display all other options except the option “One” which was selected
if “Two” is also selected in second repeat, both options “One” and “Two” should not display in subsequent repeats,
the repeat should continue until the all options are selected, then repeat ends at last option selected

Hi @yendor,

Josh’s solution seems exactly like what you asked. Can you elaborate on your question?

1 Like

thank you sir
but this does not work for select multiple in the first repeat, when i replaced the select one with select multiple in first repeat, it does not work
3choice_filter-display options not selected in next question.xlsx (62.5 KB)
attached is what I’ve tried but its not working too

Hi @yendor,

Do you think this might help you?

1 Like