-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for choice from previous repeat answers #381
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,9 +180,21 @@ def xml_control(self): | |
node("label", ref=itemset_label_ref), | ||
] | ||
result.appendChild(node("itemset", *itemset_children, nodeset=nodeset)) | ||
elif not self["children"] and self["list_name"]: | ||
list_name = survey.insert_xpaths(self["list_name"], self).strip() | ||
path = list_name.split("/") | ||
depth = len(path) | ||
if depth > 2: | ||
name = path[-1] | ||
nodeset = "/".join( | ||
path[:-2] + [path[-2] + "[string-length(./" + name + ") > 0]"] | ||
) | ||
itemset_children = [node("value", ref=name), node("label", ref=name)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is related to #370 because the values will be user-generated and could contain spaces. If this turns out to be a popular feature, we may want to allow users to specify |
||
result.appendChild(node("itemset", *itemset_children, nodeset=nodeset)) | ||
else: | ||
for n in [o.xml() for o in self.children]: | ||
result.appendChild(n) | ||
for child in self.children: | ||
result.appendChild(child.xml()) | ||
|
||
return result | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,3 +266,26 @@ def test_hints_are_present_within_groups(self): | |
</group>""" # noqa | ||
|
||
self.assertPyxformXform(md=md, xml__contains=[expected], run_odk_validate=True) | ||
|
||
def test_choice_from_previous_repeat_answers(self): | ||
"""Select one choices from previous repeat answers.""" | ||
xlsform_md = """ | ||
| survey | | | | | ||
| | type | name | label | | ||
| | begin repeat | rep | Repeat | | ||
| | text | name | Enter name | | ||
| | end repeat | | | | ||
| | select one fruits | fruit | Choose a fruit | | ||
| | select one ${name} | choice | Choose name | | ||
| choices | | | | | ||
| | list name | name | label | | ||
| | fruits | banana | Banana | | ||
| | fruits | mango | Mango | | ||
""" | ||
self.assertPyxformXform( | ||
md=xlsform_md, | ||
xml__contains=[ | ||
'<itemset nodeset="/pyxform_autotestname/rep[string-length(./name) > 0]">' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There shouldn't be a predicate. |
||
], | ||
run_odk_validate=True, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that
string-length(./" + name + ") > 0
is not intended to be hardcoded. It should just be whatever the contents of thechoice_filter
column is.With the following definition:
There should be no predicate at all.
With the following definition:
The predicate should be
starts-with(., "b")
.Note that the choice filter/predicate could possibly include a reference to another node (
starts-with(., ${favorite_letter}
).