Dynamic Appearance Change based on previous response

1. What is the issue? Please be detailed.
I would like to have the appearance of a question to be changed depending on the answer to a previous question.

2. What steps can we take to reproduce this issue?
Upload the files XLSForm with media files and notice in ODK Collect how the note does show that the text in the calculate field changes depending on the response to Q1, however, this doesn't dynamically change the appearance for Q2.

3. What have you tried to fix the issue?
Putting the actual text 'columns-2 no-buttons' instead of the ${calc_appearance} into the appearance field text in from the calculate field, but this is static and not what I want.

4. Upload any forms or screenshots you can share publicly below.
selects_example.xlsx (19.9 KB)
Selects_media.zip (3.3 MB)

I tried a similar thing with the parameters field and got an error when trying to upload the XLSForm to Central:

"The XLSForm could not be converted: Expecting parameters to be in the form of 'parameter1=value parameter2=value'."

selects_example_w_param.xlsx (20.3 KB)

Nope, you cant do this as appearances are evaluated as static strings when rendering the form.

I would like to have the appearance of a question to be changed depending on the answer to a previous question.

What you can possibly do is have two versions of the question - one with each desired appearance - and flip between them with a suitable relevant expression (based on the previous question) to ensure only one is ever shown.

2 Likes

So I'm back to this issue, but this time it is slightly different. This time I have a multilingual form that I want to display differently for different languages, so still wanting dynamic appearance, but realize that currently isn't possible.

I have a select one question with a couple dozen responses. In one language I want to have the 'minimal' appearance and for another language, I want to have responses with images and audio that plays when the response is chosen, which would probably be 'no-buttons'.

Is there a way to use an expression in the relevant column with the display language as a variable that could control this?

Based on my searching on the forums, this is what I found and it doesn't look like this is possible.

AFAIK the current display language isn't exposed via any form-accessible metadata, nor a special custom XPath function, such that you could immediately use it in a relevant expression for your desired purpose [that said, either of these might make for an interesting future feature proposal... :thinking:]

However, with a little creativity you can accomplish much the same yourself.

In the following form, I use a jr:choice-name() function to get the translated label for a select question. Because I dont actually want to display this question I always hide it with a relevant=false. For the translated label of the (sole) option for this select I put in the language identifier; in this way, the build-in translation apparatus will give me back the current selected language id! :tada:

The only complication is getting this to be recalculated appropriately, since changing the language option does not automatically trigger form re-calculations, alas. So instead, I explicitly trigger recalculating the language whenever a specific initial required question is changed (ie name). [if you dont do this, you are stuck with the default initial language, because the language calculation never gets recalculated until you do the final submit, which is too late]. Once you have the language identifier you can, as you suggest, use it in relevant calculations to show/hide different language-dependent form content.

Have a play with this form and see if you can adapt it to your needs:

GetLanguage.xlsx (18.9 KB)



Caveat: you must go back and change the value of the triggering question if you subsequently change your language selection, for language to be recalculated.

[looking back, this appears similiar/same to an approach suggested previously by @danbjoseph ]

Thanks for your creative, detailed, and quick response!

This is a good workaround that while not ideal, could work in every case except for needing to have the first question being one that would be affected by the trigger. That is not the case with my form but this does bring me back to the original question regarding specifying a dynamic appearance.

You said that it is currently rendered as a static string, what would be required to design this in a way to make it dynamic? Would this be a good feature request?

The main situation I'm working with is designing multilingual forms to be filled out by people literate in French or English, but also making these forms more accessible for nonliterate monolingual farmers who speak a minority language. I say nonliterate to make a distinction that is often not talked about in detail, but literacy is often regarded by literate people as a binary thing, you either know how to read, or you don't, when there are massive gaps between those at the lower end of the spectrum that literally do not know how to use a book (yes those people still exist! This IT support comedy sketch is an exaggeration of rare interactions I've had), to those who can recognize some numbers or letters, to those who can sound out basic words with diligent effort, etc., etc.

I currently use audio and images a lot since any text displayed in the label is mostly irrelevant to a nonliterate person. My main issue here is for select one/multiple questions with regards to how the responses are displayed. For a literate person, it would be easiest to have the default radio buttons displayed vertically (the default) or autocomplete or minimal in some cases. For the illiterate users, I typically use: no-buttons and have audio play when the response image is selected similar to this screenshot:

While doing separate questions with a relevant expression using the selected language as a variable as you and @danbjoseph described, this essentially makes the form n times bigger where n= the # of languages the form uses if you needed different appearances for each language. It would at least double the size of the form in my case and it would also make analysis much more cumbersome.

I hope I'm not coming across as lazy in not wanting to incorporate these workarounds. I think the main thing that is often frustrating for me is that I'm designing workflows for illiterate people who require things to be displayed very simply, preferably w/o text so as not to be overwhelmed/confused. Since these folks are ignored in much of the broader world of tech design, most tools are completely inaccessible to them, which is why I found ODK in the first place! ODK seems to be the best adapted to cater to such a broad diversity of users, including those who are illiterate. I just want to continue to push the boundaries to make it easier/more accessible to those users, but I'm ignorant as to how much work/effort is required to make those structural changes to the underlying foundation.

This totally makes sense and like you say, it's an area we're interested in improving and making sure continues to be well-supported.

What we're not familiar with is the hybrid case you're describing -- wanting to have a tool that's accessible for folks with low-literacy but also wanting it to be fast to fill out for high/higher literacy folks. Until we hear about more scenarios with this kind of need, it's not something we are ready to consider designing features for. Maybe something you could do is write a more general post about your use case to see if there are others with similar needs.

In the specific example you share with the grid of 9 images, it doesn't feel like the image display would be a big disadvantage for literate users. Is it that you have complex images or big lists of choices that become harder to navigate visually? Have you confirmed that it's a big barrier/inconvenience to those more literate users?

One thing you could explore doing as a stop gap is having two versions of your form. You could have a base form which includes both text and supporting media and a set of appearances targeted at one kind of user. And then you could generate a derived form by changing the appearances. You could then assign one form or the other to different App Users so that any given individual only sees one. You could do this manually with search and replace each time you update the form or possibly automate it.