Cht-core: XForm with single top level field/group does not load

Created on 18 Feb 2016  路  4Comments  路  Source: medic/cht-core

The form used for testing #1430 previously worked in medic-webapp, but now in 2710 does not load and gives an error: Error loading form. ["TypeError: Cannot read property 'add' of undefined"].

This isn't blocking any work for a deployment, but we should investigate to avoid rejecting valid XForm (if this form is indeed valid).

The only change to make the form work was to remove the <group appearance="field-list" ref="/parentheses_test/test"> and its respective close tag.

Below are the two versions:

Previously working XForm:

<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <h:head>
    <h:title>Test: Parentheses</h:title>
    <model>
      <instance>
        <parentheses_test id="test-parentheses" version="2015-10-10">
          <test>
            <num/>
            <calc/>
            <test1/>
            <test2/>
            <test3/>
            <test4/>
          </test>
          <meta>
            <instanceID/>
          </meta>
        </parentheses_test>
      </instance>
      <bind constraint=". &gt;= 0" jr:constraintMsg="Number must be 0 or more" nodeset="/parentheses_test/test/num" type="int"/>
      <bind calculate="if( /parentheses_test/test/num &gt;2, &quot;true&quot;,&quot;false&quot;)" nodeset="/parentheses_test/test/calc" type="string"/>
      <bind nodeset="/parentheses_test/test/test1" readonly="true()" relevant="( /parentheses_test/test/num  &gt; 0) and ( /parentheses_test/test/calc  = &quot;true&quot;)" type="string"/>
      <bind nodeset="/parentheses_test/test/test2" readonly="true()" relevant="( /parentheses_test/test/num  &gt; 0) and ( /parentheses_test/test/calc  != &quot;true&quot;)" type="string"/>
      <bind nodeset="/parentheses_test/test/test3" readonly="true()" relevant=" /parentheses_test/test/num  &gt; 0 and  /parentheses_test/test/calc  = &quot;true&quot;" type="string"/>
      <bind nodeset="/parentheses_test/test/test4" readonly="true()" relevant=" /parentheses_test/test/num  &gt; 0 and  /parentheses_test/test/calc  != &quot;true&quot;" type="string"/>
      <bind calculate="concat('uuid:', uuid())" nodeset="/parentheses_test/meta/instanceID" readonly="true()" type="string"/>
    </model>
  </h:head>
  <h:body class="pages">
    <group appearance="field-list" ref="/parentheses_test/test">
      <label>Parentheses Test</label>
      <input ref="/parentheses_test/test/num">
        <label>Enter a value</label>
      </input>
      <input ref="/parentheses_test/test/test1">
        <label>(<output value=" /parentheses_test/test/num "/> &gt; 0) and (<output value=" /parentheses_test/test/calc "/> = &quot;true&quot;)</label>
      </input>
      <input ref="/parentheses_test/test/test2">
        <label>(<output value=" /parentheses_test/test/num "/> &gt; 0) and (<output value=" /parentheses_test/test/calc "/> != &quot;true&quot;)</label>
      </input>
      <input ref="/parentheses_test/test/test3">
        <label>
          <output value=" /parentheses_test/test/num "/>&gt; 0 and <output value=" /parentheses_test/test/calc "/> = &quot;true&quot;</label>
      </input>
      <input ref="/parentheses_test/test/test4">
        <label>
          <output value=" /parentheses_test/test/num "/>&gt; 0 and <output value=" /parentheses_test/test/calc "/> != &quot;true&quot;</label>
      </input>
    </group>
  </h:body>
</h:html>

Working version, without group tag:

<?xml version="1.0"?>
<h:html xmlns="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <h:head>
    <h:title>Test: Parentheses</h:title>
    <model>
      <instance>
        <parentheses_test id="test-parentheses" version="2015-10-10">
          <test>
            <num/>
            <calc/>
            <test1/>
            <test2/>
            <test3/>
            <test4/>
          </test>
          <meta>
            <instanceID/>
          </meta>
        </parentheses_test>
      </instance>
      <bind constraint=". &gt;= 0" jr:constraintMsg="Number must be 0 or more" nodeset="/parentheses_test/test/num" type="int"/>
      <bind calculate="if( /parentheses_test/test/num &gt;2, &quot;true&quot;,&quot;false&quot;)" nodeset="/parentheses_test/test/calc" type="string"/>
      <bind nodeset="/parentheses_test/test/test1" readonly="true()" relevant="( /parentheses_test/test/num  &gt; 0) and ( /parentheses_test/test/calc  = &quot;true&quot;)" type="string"/>
      <bind nodeset="/parentheses_test/test/test2" readonly="true()" relevant="( /parentheses_test/test/num  &gt; 0) and ( /parentheses_test/test/calc  != &quot;true&quot;)" type="string"/>
      <bind nodeset="/parentheses_test/test/test3" readonly="true()" relevant=" /parentheses_test/test/num  &gt; 0 and  /parentheses_test/test/calc  = &quot;true&quot;" type="string"/>
      <bind nodeset="/parentheses_test/test/test4" readonly="true()" relevant=" /parentheses_test/test/num  &gt; 0 and  /parentheses_test/test/calc  != &quot;true&quot;" type="string"/>
      <bind calculate="concat('uuid:', uuid())" nodeset="/parentheses_test/meta/instanceID" readonly="true()" type="string"/>
    </model>
  </h:head>
  <h:body class="pages">
    <label>Parentheses Test</label>
    <input ref="/parentheses_test/test/num">
      <label>Enter a value</label>
    </input>
    <input ref="/parentheses_test/test/test1">
      <label>(<output value=" /parentheses_test/test/num "/> &gt; 0) and (<output value=" /parentheses_test/test/calc "/> = &quot;true&quot;)</label>
    </input>
    <input ref="/parentheses_test/test/test2">
      <label>(<output value=" /parentheses_test/test/num "/> &gt; 0) and (<output value=" /parentheses_test/test/calc "/> != &quot;true&quot;)</label>
    </input>
    <input ref="/parentheses_test/test/test3">
      <label>
        <output value=" /parentheses_test/test/num "/>&gt; 0 and <output value=" /parentheses_test/test/calc "/> = &quot;true&quot;</label>
    </input>
    <input ref="/parentheses_test/test/test4">
      <label>
        <output value=" /parentheses_test/test/num "/>&gt; 0 and <output value=" /parentheses_test/test/calc "/> != &quot;true&quot;</label>
    </input>
  </h:body>
</h:html>
Bug

All 4 comments

@abbyad is this one still relevant?

Encountered the same error code while helping @guptasanchay debug a form, so I would say that this is still relevant.

If we don't plan to fix this soon we should make sure that anyone building forms is aware of this _quirk_. cc @ngamita, @derickl

A single field at the top level does not work either giving the same error as a single group.

In this commit on a test form you can see the change necessary to make a non-working form load properly.

Added documentation label so that we make sure this is at least covered in documentation until it is fixed.

Was this page helpful?
0 / 5 - 0 ratings