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?
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... 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
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.
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!
@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.