convert-contact-form
can break contact form with nested groups in init
group
#640
Labels
Type: Bug
Fix something that isn't working as intended
Describe the bug
The
convert-contact-forms
action contains logic that manually manipulates the order of elements in thebody
section of the form xml. Basically, when the form contains a/data/contact
group it will try to update thebody
section so that the/data/contact
group is nested inside of the/data/init
group.So, an xml with a
body
like:becomes:
Unfortunately the this logic seems to be bugged when
/data/init
contains a nested group. In that case, the form xml actually ends up being converted into:Notice that
/data/contact
is now actually instead/data/init/non_relevant_group
.This does not seem to have any negative effects except when
/data/init/non_relevant_group
is non-relevant and/data/contact
hascalculate
fields that should be evaluated. When that happens the/data/contact
calculation
s will not be evaluated since they are regarded by Enketo as non-relevant.To Reproduce
Create a contact-create form with the following contents (does not have to result in a "valid" contact:
Convert/upload the form with cht-conf, then open the form in the CHT. Enter a value into the "Name" field.
Then, in the browser console, run
window.CHTCore.debugFormModel()
to dump the current form model data.The expected behavior is that
data/contact/first_name
should be populated with the same value you entered indata/init/fist_name_contact
. However, this will not be the case in the dumped model data. Instead,data/contact/first_name
is not populated at all (presumably because Enketo considers it to be non-relevant).Expected behavior
I believe that if the
convert-contact-forms
action simply nested/data/contact
inside/data/init
(as a sibling of/data/init/non_relevant_group
) everything would work as expected.This
convert-contact-form
functionality was originally added in #25. I am not 100% sure, but this seems to have been a hack try to and work around medic/cht-core#8226. A better long-term solution might be to solve#8226
and then unjankify some of this contact form logic. At the very least we need more complete documentation regarding the required structure of contact forms....Additional context
Originally reported on the forum.
One final note is that it this does not seem to be related to any specific Enketo version. I have reproduced the behavior on
3.17.2
and onmaster
.The text was updated successfully, but these errors were encountered: