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

Commit

Permalink
Fix: ensure geopicker is loaded for non-nested setgeopoint actions
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelidlessness committed Jun 7, 2022
1 parent 484eb18 commit e537627
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/widget/geo/geopicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Geopicker extends Widget {
* @type {string}
*/
static get selector() {
return ':is(.question input[data-type-xml="geopoint"], .question input[data-type-xml="geotrace"], .question input[data-type-xml="geoshape"]):not([data-setvalue], [data-setgeopoint])';
return '.question [name]:not([name=""], [type="hidden"]):is(input[data-type-xml="geopoint"], input[data-type-xml="geotrace"], input[data-type-xml="geoshape"])';
}

/**
Expand Down
33 changes: 27 additions & 6 deletions test/forms/setgeopoint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
<instance>
<data id="setgeopoint">
<hidden_first_load/>
<visible_first_load/>
<visible_first_load_adjacent_action/>
<visible_first_load_nested_explicit_ref/>
<visible_first_load_nested_implied_ref/>
<visible_first_load_model_action/>
<changes/>
<location_changed/>
<meta>
Expand All @@ -22,18 +25,36 @@
</instance>

<bind nodeset="/data/hidden_first_load" type="string"/>
<bind nodeset="/data/visible_first_load" type="string"/>
<bind nodeset="/data/visible_first_load_adjacent_action" type="geopoint"/>
<bind nodeset="/data/visible_first_load_nested_explicit_ref" type="geopoint"/>
<bind nodeset="/data/visible_first_load_nested_implied_ref" type="geopoint"/>
<bind nodeset="/data/visible_first_load_model_action" type="geopoint"/>

<bind nodeset="/data/changes" type="int"/>
<bind nodeset="/data/location_changed" type="string"/>
<bind nodeset="/data/location_changed" type="geopoint"/>

<odk:setgeopoint event="some-unsupported-event odk-instance-first-load" ref="/data/hidden_first_load"/>
<odk:setgeopoint event="odk-instance-first-load" ref="/data/visible_first_load_model_action"/>
</model>
</h:head>
<h:body>
<odk:setgeopoint event="odk-instance-first-load" ref="/data/visible_first_load"/>
<input ref="/data/visible_first_load">
<label>odk-instance-first-load</label>
<odk:setgeopoint event="odk-instance-first-load" ref="/data/visible_first_load_adjacent_action"/>
<input ref="/data/visible_first_load_adjacent_action">
<label>visible_first_load_adjacent_action</label>
</input>

<input ref="/data/visible_first_load_nested_explicit_ref">
<label>visible_first_load_nested_explicit_ref</label>
<odk:setgeopoint event="odk-instance-first-load" ref="/data/visible_first_load_nested_explicit_ref"/>
</input>

<input ref="/data/visible_first_load_nested_implied_ref">
<odk:setgeopoint event="odk-instance-first-load"/>
<label>visible_first_load_nested_implied_ref</label>
</input>

<input ref="/data/visible_first_load_model_action">
<label>visible_first_load_model_action</label>
</input>

<select1 ref="/data/changes" appearance="minimal">
Expand Down
24 changes: 24 additions & 0 deletions test/spec/widget.geo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,28 @@ describe('geoshape widget', () => {

expect(geopickers.length).to.equal(0);
});

it('loads the widget when a setgeopoint odk-instance-first-load action is defined adjacent to the input', () => {
const form = loadForm('setgeopoint.xml');

form.init();

const widget = form.view.html.querySelector(
'[name="/data/visible_first_load_adjacent_action"] ~ .geopicker'
);

expect(widget).not.to.be.null;
});

it('loads the widget when a setgeopoint odk-instance-first-load action is defined in the model', () => {
const form = loadForm('setgeopoint.xml');

form.init();

const widget = form.view.html.querySelector(
'[name="/data/visible_first_load_model_action"] ~ .geopicker'
);

expect(widget).not.to.be.null;
});
});

0 comments on commit e537627

Please sign in to comment.