Skip to content

Commit

Permalink
Merge pull request #457 from gushil/fix-452-trigger-ref-hidden-question
Browse files Browse the repository at this point in the history
Triggers referring to hidden question will produce an error.
  • Loading branch information
lognaturel authored Jul 23, 2020
2 parents c46e853 + 77d44e9 commit ef8bd00
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pyxform/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ def xml_instance(self, **kwargs):

def xml_control(self):
if ("calculate" in self.bind or self.trigger) and not (self.label or self.hint):
nested_setvalues = self.get_root().get_setvalues_for_question_name(
self.name
)
if nested_setvalues:
for setvalue in nested_setvalues:
msg = (
"Trigger was added for ${%s} that refers to hidden question. This is not allowed."
% setvalue[0]
)
raise PyXFormError(msg)
return None

xml_node = self.build_xml()
Expand Down
16 changes: 16 additions & 0 deletions pyxform/tests_v1/test_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,22 @@ def test_handling_trigger_column_with_no_calculation_no_label_no_hint(self):
],
)

def test_trigger_refer_to_hidden_node_ref_gives_error(self):
self.assertPyxformXform(
name="trigger-invalid-ref",
md="""
| survey | | | | | |
| | type | name | label | trigger | calculation |
| | calculate | one | | | 5 + 4 |
| | calculate | one-ts | | ${one} | now() |
| | note | note | timestamp: ${one-ts} | | |
""",
errored=True,
error__contains=[
"Trigger was added for ${one-ts} that refers to hidden question. This is not allowed."
],
)

def test_handling_trigger_column_in_group(self):
md = """
| survey | | | | | |
Expand Down

0 comments on commit ef8bd00

Please sign in to comment.