medic / cht-core

The CHT Core Framework makes it faster to build responsive, offline-first digital health apps that equip health workers to provide better care in their communities. It is a central resource of the Community Health Toolkit.
https://communityhealthtoolkit.org
GNU Affero General Public License v3.0
466 stars 217 forks source link

Broken functions for xForm repeat_groups #7237

Closed jkuester closed 2 years ago

jkuester commented 3 years ago

Describe the bug Currently there are several functions (at least count() and position()) that are required when doing any kind of advanced logic in a repeat_group which do not seem to function at all within the CHT. When any of these functions are included in a form they cause errors to be thrown when the CHT tries to display the form.

Example Error Log ``` inbox.js?_sw-precache=5ec5cb99da4ab03e3fd1d06910e2f057:3 Error loading form Error: ["FormLogicError: Could not evaluate: count( /model/instance[1]/test_form/plant ), message: Failed to execute 'evaluate' on 'Document': Type conversion failed while evaluating the expression."] at inbox.js?_sw-precache=5ec5cb99da4ab03e3fd1d06910e2f057:3 at inbox.js?_sw-precache=5ec5cb99da4ab03e3fd1d06910e2f057:3 at inbox.js?_sw-precache=5ec5cb99da4ab03e3fd1d06910e2f057:3 at c.$digest (inbox.js?_sw-precache=5ec5cb99da4ab03e3fd1d06910e2f057:3) at inbox.js?_sw-precache=5ec5cb99da4ab03e3fd1d06910e2f057:3 at Object.completeTask (inbox.js?_sw-precache=5ec5cb99da4ab03e3fd1d06910e2f057:3) at inbox.js?_sw-precache=5ec5cb99da4ab03e3fd1d06910e2f057:3 ```

Not having this functionality prevents CHT forms from being able to do things like repeating as long as a condition is met.

To Reproduce

I have created a test form that illustrates the desired behaviors: test_form.xlsx

This form works fine when previewed in https://getodk.org/xlsform/ but does not function when loaded in the CHT.

Additional context

These issues might be (at least partially) related to the older version of enketo-core that is currently used by the CHT. This issue should be revisited after the enketo-core upgrade is completed for #6345.

jkuester commented 3 years ago

Additional context from the forum: https://forum.communityhealthtoolkit.org/t/displaying-dynamic-screens/1085/3

lorerod commented 2 years ago

Reproducible on Master

main.js?_sw-precache=2ff7a4dc4fbb91e253d7a732e47edce6:1 Error loading form. Error: ["FormLogicError: Could not evaluate: count( /model/instance[1]/test_repeat/plant ), message: Failed to execute 'evaluate' on 'Document': Type conversion failed while evaluating the expression."]
    at main.js?_sw-precache=2ff7a4dc4fbb91e253d7a732e47edce6:1:2968191
    at p.value (polyfills.js?_sw-precache=2cd50933bd1e83dcdc75f254671e4a26:1:10189)
    at p.value (polyfills.js?_sw-precache=2cd50933bd1e83dcdc75f254671e4a26:1:4280)
    at polyfills.js?_sw-precache=2cd50933bd1e83dcdc75f254671e4a26:1:21025
    at p.value (polyfills.js?_sw-precache=2cd50933bd1e83dcdc75f254671e4a26:1:10880)
    at p.value (polyfills.js?_sw-precache=2cd50933bd1e83dcdc75f254671e4a26:1:5076)
    at f (polyfills.js?_sw-precache=2cd50933bd1e83dcdc75f254671e4a26:1:13186)
    at p.value [as invoke] (polyfills.js?_sw-precache=2cd50933bd1e83dcdc75f254671e4a26:1:12865)
    at g (polyfills.js?_sw-precache=2cd50933bd1e83dcdc75f254671e4a26:1:24995)
    at FileReader.w (polyfills.js?_sw-precache=2cd50933bd1e83dcdc75f254671e4a26:1:25227)

Fixed on branch