Skip to content

Commit

Permalink
Resolves getodk#4570?
Browse files Browse the repository at this point in the history
  • Loading branch information
dimwight committed Jul 30, 2021
1 parent 5505e10 commit 758c601
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 6 deletions.
204 changes: 204 additions & 0 deletions collect_app/src/androidTest/assets/forms/empty_first_repeat.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
<?xml version="1.0"?>
<h:html xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa"
xmlns:odk="http://www.opendatakit.org/xforms" xmlns="http://www.w3.org/2002/xforms">
<h:head>
<h:title>empty_first_repeat</h:title>
<model odk:xforms-version="1.0.0">
<instance>
<data id="empty_first_repeat" version="2021-07-30 B">
<veg_yn>1</veg_yn>
<veg_type>2 3 5</veg_type>
<veg_repeat_count />
<veg_repeat jr:template="">
<veg_group>
<veg_name />
<veg_often />
</veg_group>
</veg_repeat>
<veg_repeat>
<veg_group>
<veg_name />
<veg_often />
</veg_group>
</veg_repeat>
<meta>
<instanceID />
</meta>
</data>
</instance>
<instance id="yes_no">
<root>
<item>
<label>No</label>
<name>0</name>
</item>
<item>
<label>Yes</label>
<name>1</name>
</item>
</root>
</instance>
<instance id="veg_type">
<root>
<item>
<label>Beans</label>
<name>1</name>
</item>
<item>
<label>Beet</label>
<name>2</name>
</item>
<item>
<label>Bell pepper</label>
<name>3</name>
</item>
<item>
<label>Broccoli</label>
<name>4</name>
</item>
<item>
<label>Cabbage</label>
<name>5</name>
</item>
<item>
<label>Carrot</label>
<name>6</name>
</item>
<item>
<label>Cauliflower</label>
<name>7</name>
</item>
<item>
<label>Celery</label>
<name>8</name>
</item>
<item>
<label>Corn</label>
<name>9</name>
</item>
<item>
<label>Cucumber</label>
<name>10</name>
</item>
<item>
<label>Garlic</label>
<name>11</name>
</item>
<item>
<label>Green onion</label>
<name>12</name>
</item>
<item>
<label>Kale</label>
<name>13</name>
</item>
<item>
<label>Leek</label>
<name>14</name>
</item>
<item>
<label>Lettuce</label>
<name>15</name>
</item>
<item>
<label>Radish</label>
<name>16</name>
</item>
<item>
<label>Rhubarb</label>
<name>17</name>
</item>
<item>
<label>Rutabaga/Turnip</label>
<name>18</name>
</item>
<item>
<label>Spinach</label>
<name>19</name>
</item>
<item>
<label>Sweet potato/Yam</label>
<name>20</name>
</item>
<item>
<label>Onion</label>
<name>21</name>
</item>
<item>
<label>Squash/pumpkin</label>
<name>22</name>
</item>
<item>
<label>Tomato</label>
<name>23</name>
</item>
<item>
<label>Zucchini</label>
<name>24</name>
</item>
<item>
<label>Other</label>
<name>777</name>
</item>
</root>
</instance>
<bind nodeset="/data/veg_yn" required="true()" type="string" />
<bind constraint="not(selected( /data/veg_type , '0') and (count-selected(.)&gt;1)) and
not(selected( /data/veg_type , '889') and (count-selected(.)&gt;1)) and
not(selected( /data/veg_type , '999') and (count-selected(.)&gt;1))" nodeset="/data/veg_type"
relevant=" /data/veg_yn =1" required="true()" type="string"
jr:constraintMsg="Cannot select &quot;None&quot;, &quot;889&quot; and any other answer." />
<bind calculate="count(instance('veg_type')/root/item)" nodeset="/data/veg_repeat_count"
readonly="true()" type="string" />
<bind nodeset="/data/veg_repeat" relevant=" /data/veg_yn =1" />
<bind nodeset="/data/veg_repeat/veg_group"
relevant="selected( /data/veg_type , if (position(..) != 25, string(position(..)), '777'))" />
<bind
calculate="instance('veg_type')/root/item[position()=position(current()/../..)]/label"
nodeset="/data/veg_repeat/veg_group/veg_name" readonly="true()" type="string" />
<bind constraint=".&gt;=0 and .&lt;31 or .=889"
nodeset="/data/veg_repeat/veg_group/veg_often" required="true()" type="int"
jr:constraintMsg="Mininum: 0; Maximum: 30" />
<bind nodeset="/data/meta/instanceID" readonly="true()" type="string"
jr:preload="uid" />
</model>
</h:head>
<h:body>
<select1 ref="/data/veg_yn">
<label>Did you eat vegetables…</label>
<item>
<label>No</label>
<value>0</value>
</item>
<item>
<label>Yes</label>
<value>1</value>
</item>
</select1>
<select appearance="columns-3" ref="/data/veg_type">
<label>What type(s)…</label>
<hint>…select ALL relevant choices.</hint>
<itemset nodeset="instance('veg_type')/root/item[true()]">
<value ref="name" />
<label ref="label" />
</itemset>
</select>
<group ref="/data/veg_repeat">
<label>Frequencies</label>
<repeat nodeset="/data/veg_repeat" jr:count=" /data/veg_repeat_count ">
<group appearance="field-list" ref="/data/veg_repeat/veg_group">
<label>
<output value=" ../veg_group/veg_name " />
</label>
<input ref="/data/veg_repeat/veg_group/veg_often">
<label>How often did you eat
<output value=" ../veg_name " />
?
</label>
<hint>Enter "889" for…</hint>
</input>
</group>
</repeat>
</group>
</h:body>
</h:html>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class FormHierarchyTest {
.around(new CopyFormRule("formHierarchy2.xml", null))
.around(new CopyFormRule("formHierarchy3.xml", null))
.around(new CopyFormRule("repeat_group_new.xml", null))
.around(new CopyFormRule("empty_first_repeat.xml", null))
.around(rule);

@Test
Expand Down Expand Up @@ -170,4 +171,14 @@ public void deletingLastGroupAndAddingOneShouldNotBreakHierarchy() {
.deleteGroup()
.addGroup();
}

@Test
//https://github.com/getodk/collect/issues/4570
public void empty_first_repeat() {
new MainMenuPage()
.startBlankForm("empty_first_repeat")
.clickGoToArrow()
.assertText("Beet, Bell pepper, Cabbage")
.clickOnText("Frequencies");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,23 @@ private boolean isGroupSizeLocked(FormIndex index) {
return element instanceof GroupDef && ((GroupDef) element).noAddRemove;
}

/** Override to disable this button. */
/**
* Override to disable this button.
*/
protected void showDeleteButton(boolean shouldShow) {
optionsMenu.findItem(R.id.menu_delete_child).setVisible(shouldShow);
}

/** Override to disable this button. */
/**
* Override to disable this button.
*/
protected void showAddButton(boolean shouldShow) {
optionsMenu.findItem(R.id.menu_add_repeat).setVisible(shouldShow);
}

/** Override to disable this button. */
/**
* Override to disable this button.
*/
protected void showGoUpButton(boolean shouldShow) {
optionsMenu.findItem(R.id.menu_go_up).setVisible(shouldShow);
}
Expand Down Expand Up @@ -596,14 +602,19 @@ private void refreshView(boolean isGoingUp) {
break;
}
case FormEntryController.EVENT_REPEAT: {
FormEntryCaption fc = formController.getCaptionPrompt();
if (!formController.isGroupRelevant()) {
break;
//Handles #4570 - ensures repeats are visible
boolean isFirst = fc.getMultiplicity() == 0;
//But disregard if starting a picker
boolean isPicker = shouldShowRepeatGroupPicker();
if (!isFirst || isPicker) {
break;
}
}

visibleGroupRef = currentRef;

FormEntryCaption fc = formController.getCaptionPrompt();

// Don't render other groups' children.
if (contextGroupRef != null && !contextGroupRef.isParentOf(currentRef, false)) {
break;
Expand Down

0 comments on commit 758c601

Please sign in to comment.