Reverse cascading choice

1. What is the problem? Be very detailed.
Usually, you first chose a Country after a state and in the end the town
For that You can use cascade selected.

I my case I want to choose a town, and after that, depending of the country and the state Proposing 1 of 3 questions

I try to use selected with a Choice_Filter Colum In this form :
list_name name label image Next_Question
RSS Paris Paris DP
RSS Alger Alger SE
RSS Tunis Tunis SE
RSS Geneve Genève A1
RSS Berlin Berlin A1
RSS Monaco Monaco SE
RSS Kiev Kiev DP

But I didn't know how to extract this value dependant of my town value.

2. What app or server are you using and on what device and operating system? Include version numbers.

ODK 1.21

3. What you have you tried to fix the problem?

4. What steps can we take to reproduce the problem?

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

You can do something like instance('RSS')/root/item[name=${selected_town}]/Next_Question in a calculate row. Then you can set the relevance of your question based on that calculation. If your calculate is called next_question, in the relevant column for question se, you'd have ${next_question}='SE'.

See an example of this kind of lookup at https://docs.google.com/spreadsheets/d/1mQGVWaJA4QQp3jtddMdcRSDjc1O-j_bB79GUnlj5k10/edit#gid=0

More generally, you can use any XPath expression to access values in your choice lists.

4 Likes

Thanks. That exactly what I need

Fabienne

1 Like

I have a syntax issue

Message :
Error: b"ODK Validate Errors:\n>> Something broke the parser. See above for a hint.\nError evaluating field 'tst1': The problem was located in calculate expression for ${tst1}\nXPath evaluation: Instance referenced by instance(lst_immat)/root/item/theme does not exist\nCaused by: org.javarosa.xpath.XPathMissingInstanceException: The problem was located in calculate expression for ${tst1}\nXPath evaluation: Instance referenced by instance(lst_immat)/root/item/theme does not exist\n\t... 10 more\n\nResult: Invalid"

I have try this formula in calculate column

instance('lst_immat')/root/item[name=${pays_immat}]/theme

In the choices sheets I have

list_name	name		label	theme
lst_immat	Albanie		AL		Pays tiers
lst_immat	Allemagne	D		UE
lst_immat	Andorre		AND		UE
lst_immat	Arménie		AM		Pays tiers
lst_immat	Autriche	A		UE

What could be wrong ?

Oops, I forgot one annoying part of this. pyxform, the tool that converts forms from XLSForm to XForms, doesn't have explicit support for this kind of lookup. Right now it sees your simple list of choices and builds the choice list internally to the form rather than in a separate instance. You have to force the creation of the instance by having a choice filter on that choice list somewhere in your form.

The trick I usually use is have a question that just has explanation text or a summary but that actually is a select_one with a filter that leaves no choices. See the form I linked to for an example. You can always put that in a field-list so it's in the same screen as another question.

In your case, you'd have something like

type					name		label			choice_filter
select_one lst_immat	explanation	Some text here	name = 'fake'

Two issues are open that relate to making this kind of thing easier: https://github.com/XLSForm/pyxform/issues/203 and https://github.com/XLSForm/pyxform/issues/176

Perfect !
It works

Thanks a lot

Le lun. 6 mai 2019 à 22:30, Hélène Martin via ODK Forum noreply@forum.getodk.org a écrit :

Any reason not to simply hide this 'fake' select_one with relevant=false()? It should still be sufficient to trigger pyxform to 'instance-ize' its options so that you can then look them up with XPath.

I didn't think of it? :grimacing:

Yes, that does seem simpler, thanks! I'll do that in the future.

Please could you share an XLSForm example of this kind of lookup ?