Repeat questions depending upon selection?

What is the problem? Please be detailed.
suppose a user selects a division from a list of choices, now there are multiple districts under a single division which are being mapped using choice_filter .
Now we want some fixed question for each district falling under the selected division dynamically ?

following are division choices

list_name name label division

division IND00901 AGRA
division IND00902 ALIGARH
division IND00903 ALLAHABAD
division IND00904 AZAMGARH

following are the dist choices mapped with corresponding divsion.

dist IND00901015 AGRA IND00901
dist IND00901016 FEROZABAD IND00901
dist IND00901017 MAINPURI IND00901
dist IND00901014 MATHURA IND00901
dist IND00902012 ALIGARH IND00902
dist IND00902070 ETAH IND00902
dist IND00902013 HATHRAS IND00902
dist IND00902071 KANSHIRAM IND00902

now if user selects Agra(IND00901) then we want to ask fixed questions such as no of workers etc. for each of dist under that division (ie AGRA,Ferozabad ,Manipur )

How can we make this happen.Thanks in advance!

What ODK tool and version are you using? And on what device and operating system version?

What steps can we take to reproduce the problem?

What you have you tried to fix the problem?

Anything else we should know or have? If you have a test form or screenshots or logs, attach here.

Hi @Adarsh_Bisht,

You can try using a choice_filter column in your survey worksheet with dist = ${division}. Please see the XLSFORM tutorial below page 17.

XLSFORM tutorial_edSouirji.pdf (956.1 KB)

Good luck

Hi @Souirji_Abdelghani i think i have not clearly explained the problem,
I am using choice filter to show the disctrict according to the division,
What i want is to ask 3 same questions for each district dynamically one by one.Thanks

Hi @Adarsh_Bisht,

It would be good if you could upload a sample form the way you designed it.

1 Like

@Adarsh_Bisht or may you apload your form in word format. Way i see it you have to use repeats and nested repeats together with the question filters.

A post was split to a new topic: Structuring a table of questions for odk form

This is possible but requires a little knowledge of XML and XPath as far as I know!

Here is a sample form showing one approach. Note that I had to look at the XML to figure out how to get the district count and the district name. I added a notes column to try to explain the details. You should be able to start from this and add any questions you need in the district_questions repeat. Note also that repeat-over-filtered-choices is the filename I used which then becomes the document root. If you change the XLSX filename, you'll need to replace the name in the calculations as well.

If anyone knows of a more straightforward way to achieve the same thing I'd be very interested in seeing it! This is a really useful pattern so perhaps we could think of way for XLSForm to make this friendlier if it doesn't already exist.


Hi,Thanks for the reply.
I tried your form .but i am getting following error.
'Error evaluating field district_count: The problem was located in calculate expression for /repeat-over-filtered-choices/disctrict_count Xpath evaluation:Instance refrenced by instance (dist)/root/ item does not exist.

Please help me to resolve this issue.

@Adarsh_Bisht did you try it exactly as it is with the latest version of ODK Collect?

yes..i did not change a thing,just converted the form to xfrom using XLSfrom app.
still getting following error in ODK validate.PFA the xfrom

">> Something broke the parser. See above for a hint.
java.lang.RuntimeException: Error evaluating field 'district_count': The problem was located in calculate expression for /repeat-over-filtered-choices/district_count
XPath evaluation: Instance referenced by instance(dist)/root/item does not exist

repeat-over-filtered-choices.xml (3.0 KB)

I had initially done the conversion with the latest version of pyxform and that worked without error. I also just verified that also works and hopefully will be an easy one for you to try.

I'm surprised that there would be a tool out there that doesn't do the conversion right. What tool is it exactly and what is its version?

1 Like

Hi @LN I uploaded the xls file without changing anything to still getting the same error.Below is the snippet i took .

That is very strange. I just downloaded it as an XLS document again from my link above and the conversion worked without any problems at Perhaps you could try another one of the converters listed.

repeat-over-filtered-choices.xml (6.7 KB) is the converted form if you just want to check that it suits your needs.