Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
[Hacky] Fix nested repeats with relevance
Browse files Browse the repository at this point in the history
This is a targeted fix for one user, addressing a case where relevance on a nested/grouped repeat only works for the first top-level repeat. It causes a test failure for another use case, which provides helpful testing context and sort of hints at a likely direction for a more general fix.
  • Loading branch information
eyelidlessness committed Aug 27, 2021
1 parent f9a5060 commit 31993ef
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/js/relevant.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ export default {
* but currently has 0 repeats, the context will not be available. This same logic is applied in output.js.
*/
let context = p.path;
if ( getChild( node, `.or-repeat-info[data-name="${p.path}"]` ) && !getChild( node, `.or-repeat[name="${p.path}"]` ) ) {
context = null;
const repeatInfo = getChild( node, `.or-repeat-info[data-name="${p.path}"]` );
if ( repeatInfo != null && !getChild( node, `.or-repeat[name="${p.path}"]` ) ) {
this.form.repeats.add( repeatInfo );
}

/*
Expand Down
158 changes: 158 additions & 0 deletions test/forms/core-804-nested-repeat-relevant.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
<?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:odk="http://www.opendatakit.org/xforms" xmlns:orx="http://openrosa.org/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<h:head>
<h:title>enketo-repeat-bug</h:title>
<model odk:xforms-version="1.0.0">
<instance>
<data id="enketo-repeat-bug" version="2021081700">
<field_asset_exists>yes</field_asset_exists>
<field_asset_rpt jr:template="">
<field_asset_rpt_grp>
<asset_name />
<documentation_exists />
<documentation_rpt jr:template="">
<documentation_rpt_grp>
<documentation_type />
<documentation_file />
<documentation_photo />
</documentation_rpt_grp>
</documentation_rpt>
<documentation_rpt>
<documentation_rpt_grp>
<documentation_type />
<documentation_file />
<documentation_photo />
</documentation_rpt_grp>
</documentation_rpt>
<instrumentation_exists />
<instrumentation_rpt jr:template="">
<instrumentation_rpt_grp>
<instrumentation_tag />
<instrumentation_measurement />
<instrumentation_measurement_other />
</instrumentation_rpt_grp>
</instrumentation_rpt>
<instrumentation_rpt>
<instrumentation_rpt_grp>
<instrumentation_tag />
<instrumentation_measurement />
<instrumentation_measurement_other />
</instrumentation_rpt_grp>
</instrumentation_rpt>
</field_asset_rpt_grp>
</field_asset_rpt>
<field_asset_rpt>
<field_asset_rpt_grp>
<asset_name />
<documentation_exists>no</documentation_exists>
<documentation_rpt>
<documentation_rpt_grp>
<documentation_type />
<documentation_file />
<documentation_photo />
</documentation_rpt_grp>
</documentation_rpt>
<instrumentation_exists>yes</instrumentation_exists>
<instrumentation_rpt>
<instrumentation_rpt_grp>
<instrumentation_tag />
<instrumentation_measurement />
<instrumentation_measurement_other />
</instrumentation_rpt_grp>
</instrumentation_rpt>
</field_asset_rpt_grp>
</field_asset_rpt>
<meta>
<instanceID />
</meta>
</data>
</instance>

<bind nodeset="/data/field_asset_exists" required="true()" type="string" />
<bind nodeset="/data/field_asset_rpt" relevant="selected( /data/field_asset_exists , 'yes')" />
<bind nodeset="/data/field_asset_rpt/field_asset_rpt_grp/asset_name" type="string" />
<bind nodeset="/data/field_asset_rpt/field_asset_rpt_grp/documentation_exists" required="true()" type="string" />
<bind nodeset="/data/field_asset_rpt/field_asset_rpt_grp/documentation_rpt" relevant="selected( ../documentation_exists , 'yes')" />
<bind nodeset="/data/field_asset_rpt/field_asset_rpt_grp/documentation_rpt/documentation_rpt_grp/documentation_type" required="true()" type="string" />
<bind nodeset="/data/field_asset_rpt/field_asset_rpt_grp/documentation_rpt/documentation_rpt_grp/documentation_file" type="binary" />
<bind nodeset="/data/field_asset_rpt/field_asset_rpt_grp/documentation_rpt/documentation_rpt_grp/documentation_photo" orx:max-pixels="1000" relevant=" ../documentation_file = ''" type="binary" />
<bind nodeset="/data/field_asset_rpt/field_asset_rpt_grp/instrumentation_exists" required="true()" type="string" />
<bind nodeset="/data/field_asset_rpt/field_asset_rpt_grp/instrumentation_rpt" relevant="selected( ../instrumentation_exists , 'yes')" />
<bind nodeset="/data/field_asset_rpt/field_asset_rpt_grp/instrumentation_rpt/instrumentation_rpt_grp/instrumentation_tag" type="string" />
<bind nodeset="/data/field_asset_rpt/field_asset_rpt_grp/instrumentation_rpt/instrumentation_rpt_grp/instrumentation_measurement" required="true()" type="string" />
<bind nodeset="/data/field_asset_rpt/field_asset_rpt_grp/instrumentation_rpt/instrumentation_rpt_grp/instrumentation_measurement_other" relevant="selected( ../instrumentation_measurement , 'other')" required="true()" type="string" />
<bind jr:preload="uid" nodeset="/data/meta/instanceID" readonly="true()" type="string" />
</model>
</h:head>
<h:body>
<select1 ref="/data/field_asset_exists"><label>Is there at least 1 field asset?</label>
<item><label>Yes</label>
<value>yes</value>
</item>
<item><label>No</label>
<value>no</value>
</item>
</select1>
<group ref="/data/field_asset_rpt"><label>Field asset</label>
<repeat nodeset="/data/field_asset_rpt">
<group ref="/data/field_asset_rpt/field_asset_rpt_grp"><label><output value=" ../field_asset_rpt_grp/asset_name " /></label><input ref="/data/field_asset_rpt/field_asset_rpt_grp/asset_name"><label>Asset name</label></input>
<select1 ref="/data/field_asset_rpt/field_asset_rpt_grp/documentation_exists"><label>Is there at least 1 piece of documentation?</label>
<item><label>Yes</label>
<value>yes</value>
</item>
<item><label>No</label>
<value>no</value>
</item>
</select1>
<group ref="/data/field_asset_rpt/field_asset_rpt_grp/documentation_rpt"><label>Documentation</label>
<repeat nodeset="/data/field_asset_rpt/field_asset_rpt_grp/documentation_rpt">
<group ref="/data/field_asset_rpt/field_asset_rpt_grp/documentation_rpt/documentation_rpt_grp"><label><output value=" ../documentation_rpt_grp/documentation_type " /></label>
<select1 ref="/data/field_asset_rpt/field_asset_rpt_grp/documentation_rpt/documentation_rpt_grp/documentation_type"><label>Documentation type</label>
<item><label>Drawing set</label>
<value>drawing_set</value>
</item>
<item><label>Maintenance schedule</label>
<value>maintenance_schedule</value>
</item>
<item><label>Other</label>
<value>other</value>
</item>
</select1>
<upload mediatype="application/*" ref="/data/field_asset_rpt/field_asset_rpt_grp/documentation_rpt/documentation_rpt_grp/documentation_file"><label>Documentation file</label>
<hint>If no file available, go to next question to take a photo</hint>
</upload>
<upload mediatype="image/*" ref="/data/field_asset_rpt/field_asset_rpt_grp/documentation_rpt/documentation_rpt_grp/documentation_photo"><label>Documentation photo</label></upload>
</group>
</repeat>
</group>
<select1 ref="/data/field_asset_rpt/field_asset_rpt_grp/instrumentation_exists"><label>Is there at least 1 piece of instrumentation?</label>
<item><label>Yes</label>
<value>yes</value>
</item>
<item><label>No</label>
<value>no</value>
</item>
</select1>
<group ref="/data/field_asset_rpt/field_asset_rpt_grp/instrumentation_rpt"><label>Instrumentation</label>
<repeat nodeset="/data/field_asset_rpt/field_asset_rpt_grp/instrumentation_rpt">
<group ref="/data/field_asset_rpt/field_asset_rpt_grp/instrumentation_rpt/instrumentation_rpt_grp"><label><output value=" ../instrumentation_rpt_grp/instrumentation_tag " /></label><input ref="/data/field_asset_rpt/field_asset_rpt_grp/instrumentation_rpt/instrumentation_rpt_grp/instrumentation_tag"><label>Instrumentation tag</label>
<hint>If available</hint></input>
<select1 ref="/data/field_asset_rpt/field_asset_rpt_grp/instrumentation_rpt/instrumentation_rpt_grp/instrumentation_measurement"><label>Instrumentation measurement</label>
<item><label>Conductivity</label>
<value>conductivity</value>
</item>
<item><label>Flow</label>
<value>flow</value>
</item>
<item><label>Other</label>
<value>other</value>
</item>
</select1><input ref="/data/field_asset_rpt/field_asset_rpt_grp/instrumentation_rpt/instrumentation_rpt_grp/instrumentation_measurement_other"><label>Specify other instrumentation measurement</label></input>
</group>
</repeat>
</group>
</group>
</repeat>
</group>
</h:body>
</h:html>

0 comments on commit 31993ef

Please sign in to comment.