This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: global initialization of widgets where repeat count is zero (#994)
- Loading branch information
1 parent
f37eed2
commit 75cc989
Showing
3 changed files
with
79 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?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>Global init of widgets in repeat count (default=0)</h:title> | ||
<model odk:xforms-version="1.0.0"> | ||
<instance> | ||
<data id="repeat-count-widget-global-init"> | ||
<rep-count/> | ||
<rep jr:template=""> | ||
<grp_plot> | ||
<plot_id/> | ||
<plot_size/> | ||
<plot_crops/> | ||
</grp_plot> | ||
</rep> | ||
<rep> | ||
<grp_plot> | ||
<plot_id/> | ||
<plot_size/> | ||
<plot_crops/> | ||
</grp_plot> | ||
</rep> | ||
<meta> | ||
<instanceID/> | ||
</meta> | ||
</data> | ||
</instance> | ||
<bind nodeset="/data/rep-count" type="int"/> | ||
<bind nodeset="/data/rep/dec" type="decimal"/> | ||
<bind jr:preload="uid" nodeset="/data/meta/instanceID" readonly="true()" type="string"/> | ||
</model> | ||
</h:head> | ||
<h:body> | ||
<input ref="/data/rep-count"> | ||
<label>Repeat count</label> | ||
</input> | ||
<group ref="/data/rep"> | ||
<label>Rep</label> | ||
<repeat jr:count="/data/rep-count" nodeset="/data/rep"> | ||
<input ref="/data/rep/dec"> | ||
<label>Decimal input</label> | ||
</input> | ||
</repeat> | ||
</group> | ||
</h:body> | ||
</h:html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import events from '../../src/js/event'; | ||
import loadForm from '../helpers/load-form'; | ||
|
||
describe('Widgets controller', () => { | ||
it('globally initializes widgets which are only present in a repeat instance with count=0 on load', () => { | ||
const form = loadForm('repeat-count-widget-global-init.xml'); | ||
|
||
form.init(); | ||
|
||
const setRepeatCount = () => { | ||
/** @type {HTMLInputElement} */ | ||
const countControl = form.view.html.querySelector( | ||
'input[name="/data/rep-count"]' | ||
); | ||
|
||
countControl.value = '1'; | ||
|
||
countControl.dispatchEvent(events.Change()); | ||
}; | ||
|
||
expect(setRepeatCount).not.to.throw(); | ||
}); | ||
}); |