Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pyxform/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def node(*args, **kwargs) -> DetachableElement:
kwargs -- attributes
returns a xml.dom.minidom.Element
"""
blocked_attributes = {"tag"}
# blocked_attributes = {"tag"}
tag = args[0] if len(args) > 0 else kwargs["tag"]
args = args[1:]
result = DetachableElement(tag)
Expand All @@ -116,7 +116,9 @@ def node(*args, **kwargs) -> DetachableElement:

# Convert the kwargs xml attribute dictionary to a xml.dom.minidom.Element.
for k, v in kwargs.items():
if k in blocked_attributes:
# if k in blocked_attributes:
# continue
if k == "tag" and v == tag:
continue
if k == "toParseString":
if v is True and len(unicode_args) == 1:
Expand Down
53 changes: 53 additions & 0 deletions tests/test_tag_attribute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from tests.pyxform_test_case import PyxformTestCase

"""
Ensures that fields marked with 'hidden' in the instance::tag column
get the tag="hidden" attribute in the compiled XForm.
"""


class TagRestrictionTest(PyxformTestCase):
"""Test cases for tag attribute functionality."""

def test_instance_tag_hidden_attribute(self):
"""Test that fields with instance::tag 'hidden' get tag='hidden' attribute."""
self.assertPyxformXform(
name="test_hidden_tags",
md="""
| survey | | | | |
| | type | name | label | instance::tag |
| | text | patient_name | Patient Name | |
| | integer | patient_age_years | Age in Years | hidden |
| | integer | patient_age_months | Age in Months | hidden |
| | begin group | data | Data Group | hidden |
| | text | field1 | Field 1 | |
| | end group | | | |
""",
xml__contains=[
'<patient_age_years tag="hidden"/>',
'<patient_age_months tag="hidden"/>',
'<data tag="hidden">',
"<patient_name/>", # Should NOT have tag attribute
"<field1/>",
],
)

def test_nested_groups_with_hidden_tags(self):
"""Test hidden tags work with nested groups."""
self.assertPyxformXform(
name="test_nested_hidden",
md="""
| survey | | | | |
| | type | name | label | instance::tag |
| | begin group | outer_group | Outer Group | |
| | text | field1 | Field 1 | |
| | begin group | inner_group | Inner Group | hidden |
| | text | field2 | Field 2 | |
| | end group | | | |
| | end group | | | |
""",
xml__contains=[
'<inner_group tag="hidden">',
"<outer_group>", # Should NOT have tag attribute
],
)
Loading