1. What is the issue? Please be detailed.
XForm setvalue action (aka XLSForm trigger) behaves differently - and incorrectly? - when performed within repeat groups by Enketo than the behavior of same under Collect. Specifically, in Collect, a control within a repeat iteration whose value triggered by another question in the same repeat group, will be correctly updated when the source triggering question in that iteration is modified. However, under Enketo, whenever the source triggering question changes - irregardless of what repeat iteration you are currently in - only the triggered question in the first repeat iteration is updated (!)
2. What steps can we take to reproduce this issue?
Run the following form under Enketo vs Collect:
RepeatWithTrigger.xlsx (14.4 KB)
If you run this under Enketo, whenever you answer or change the (triggering) age
question, only the (triggered) age_ts
in the first iteration is updated. You can see when you add more iterations and enter another age, the timestamp in the first iteration keeps changing; wheas all subsequent timestamps remain null.
However, if you run the same form under Collect, whenever you answer an age
only the age_ts
of the same iteration is updated, which is the expected and desired behavior.
I have further verified this by looking at the actual submitted data from each client. After running the form once under both Enketo first and then Collect, and entering the same data for 3 repeat iterations, the resulting dataset submitted to Central is [ignore the last 2 entries which are from an earlier test]:
Shown in yellow is the data from Collect, showing the 3 iterations with each new age
with its corresponding age_ts
timestamp. Showin in red is the submission data from Enketo, showing only the first repeat iteration has its age_ts
timestamp set; for the remaining 2 iterations age_ts
remains null.
3. What have you tried to fix the issue?
There appears to be no workaround; setvalue within a repeat group does not behave as expected under Enketo. I suspect the problem may lie with the fact the setvalue action ref for questions within a repeat is not interpreted to be relative to the current iteration under Enketo, whereas this setvalue ref is correctly handled under Collect.
@LN I did look thru https://github.com/enketo/enketo/issues/298, but as best I can tell (and I may be wrong!) this was mostly about misbehavior of specifically the asynchronous odk:setgeopoint functionality in repeats under Enketo, particularly in relation to odk-new-repeat events. Whereas what's described here is more the basic (and synchronous!) xform-value-changed event/setvalue action Enketo-repeat behavior.
Although, that said, could it be possible that the root cause here is the same? That is, in both cases, it is actually because the ref - either for setvalue or odk:setgeopoint - is not being handled correctly under Enketo within repeat groups?
Please note, I observe the same incorrect behavior - under Enketo - when I tried an xform-value-changed event with a setgeopoint action [ala Spec proposal: expose xforms-value-changed event with odk:setgeopoint action in XLSForm, which is how I ended up down this rabbit hole...]. Once again, this works as expected under Collect, but the same under Enketo updates the geopoint of the first iteration only:
As a consequence, neither regular setvalue triggers nor the existing xform-value-changed background GPS capture appear to work as expected under Enketo inside repeat groups. I suspect this is an Enketo bug; if you agree I can open a github issue tracker for it (or 2, if you want a separate one for each action type?). I have confirmed both cases do appear to behave as expected under Collect.