How can I use relevance to only show an image field if the prior image field has a value

Hi all,

I want to make it possible to take several photos or upload them in my form.
For several pictures, I came across the solution to use relevant. Here I am using ${photo1} in the following image field, to only appear when something is uploaded.

In the ODK collect app this works fine. Though online in the enketo environment I always see all several fields of image, even though no photo is uploaded yet.

Is there a solution to hide the other image fields and only make them appear when a first photo is uploaded?
Is my function correct?

Best and thanks.

What server are you using with Enketo? My guess is that it's not ODK Central.

As noted at When are expressions in a form recomputed? - #9 by LN, we recommend that organizations deploying Enketo configure it to opt into aligning relevance behavior with Collect (see exclude non-relevant in https://enketo.github.io/enketo-express/tutorial-10-configure.html).

I´ve installed ODK Central on our own server following the ODK instructions.

I wasn´t aware that I also have to configure enketo, though I will have a look in how to configuring it.

Here a noob question, if I log into my server (running ubuntu) and run the command cd central it usual would go into its directory, correct?

I´ve been searching all my directory but could not find the central place.

Do I need start something or stop the docker before entering?
The ODK Central application stills works, when entered via the

You shouldn’t need to configure anything if you are using Central. What version of Central are you running?

Also, can you share your form?

Hi @yanokwa,

Thanks for your answer.

This is the output for versions:

versions:
42d83f19b30d638aae871243bce2caa0d8c6095d (v2024.1.0-1-g42d83f1)
3fb0c22b1cbdc3a6004963afcc3847a82c09307d client (v2024.1.0)
b4754cf52bfa64b1ca841bc9ccb64a38726398e8 server (v2024.1.0)

That´s the form:
ODK XLSForm AFS CA_vs2.xlsx (223.9 KB)

It´s question no.5

It´s my first form in XLS and ODK, so please forgive me if there are flaws in the form. I tried my best to follow the provided manuals.

Any news or ideas why its not working?

Sidenote: Will ODK webform will not have this issue? :wink: When will there be a first roll-out?

It looks fantastic! :tada:

Your relevance conditions are a reference to the prior image question. Instead, I believe explicitly comparing the value to blank will get the desired result consistently between Collect and Enketo. For example, instead of ${photo1_afs}, use ${photo1_afs} != ''.

Enketo doesn't convert values of other types to true/false quite right. I think in this case the change I've suggested makes the intent slightly clearer anyway.

Yes, this is something that will be aligned between Web Forms and Collect.

We're going to have it available for previews in the next Central release! We're not quite yet sure when it will be available to fill out or edit forms but will share updates as we get more certainty around that.

I believe Enketo might be correct here... :slight_smile: If the question (XML node) exists, it is true (in XPath), regardless of its value. And in this case the XPath expression is a node-set which is converted to a boolean.

Many times, I have been confused about his part of the XPath spec too (here "non-empty" does not refer to the node values but to whether there are any nodes in the node-set).

You could also double-check with the native XPath evaluator with something like this (which I think is what Enketo uses in this case):

const xmlDoc = new DOMParser().parseFromString('<data><a></a></data>', 'text/xml'); 
xmlDoc.evaluate('/data/a', xmlDoc.documentElement, null, XPathResult.BOOLEAN_TYPE).booleanValue


1 Like

Wow, thanks, and sorry about the error! That is a hard one to remember. Off the top of my head I thought it might be related to Enketo using “true” and “false” to represent boolean values (both truthy in XPath I believe) but maybe that’s only an issue after serialization?

Then I’m not totally sure what we’ll do about that aspect moving forward, stay tuned.

@Agrari did you see the pattern you used described or documented somewhere? If so, please share a link so we can amend it with the recommendation to do the explicit comparison against blank.

2 Likes

That is a hard one to remember.

Yes, it is and the way the XPath spec is written is not the most helpful imo. I think checking for the existence of a node like that in a relevant or required may potentially be helpful to check if a repeat was created. Unfortunately that means you probably cannot support the shortened XLSForm syntax by wrapping the node-set in string() e.g in the XForm output.

Enketo using “true” and “false” to represent boolean values (both truthy in XPath I believe)

Maybe, but that doesn't ring a bell to me. I certainly hope not! :scream:

2 Likes

@LN & @martijnr: Thank you for your response on this.

So, if I got it right, you recommend to use ${photo1_afs} != ''
I will try it and see its response in enekto.

I do not remember, where I saw the formulation of relevance. I´ve been on many sites. Related to the picture upload I did not find anything despite a post in this forum, which was criptic about its solution. :smiley: