Skip to content

Commit

Permalink
🐛 [DH#673] Ensure that hidden layout components are also emitted
Browse files Browse the repository at this point in the history
Reported by Laurens after discussing the 'sudden inclusion' of hidden
fields in the objects API data.

Backport-of: #4123
  • Loading branch information
sergei-maertens committed Apr 5, 2024
1 parent c99d2c6 commit f97d322
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/openforms/formio/rendering/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class ContainerMixin:
def is_visible(self) -> bool:
# fieldset/editgrid components do not support the showInFoo properties, so we don't use the super
# class.
if self.mode == RenderModes.export:
# In registration mode, we need to treat layout/container nodes as visible so
# that their children are emitted too.
if self.mode in {RenderModes.export, RenderModes.registration}:
return True

# We only pass the step data, since frontend logic only has access to the current step data.
Expand Down
37 changes: 36 additions & 1 deletion src/openforms/formio/rendering/tests/test_component_node.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from unittest.mock import patch

from django.test import TestCase
from django.test import TestCase, tag

from openforms.submissions.rendering import Renderer, RenderModes
from openforms.submissions.tests.factories import SubmissionFactory

from ..constants import RenderConfigurationOptions
from ..nodes import ComponentNode
from ..registry import Registry
from ..structured import render_json


class FormNodeTests(TestCase):
Expand Down Expand Up @@ -363,6 +364,40 @@ def test_explicitly_hidden_component_not_skipped_when_registration(self):
self.assertEqual(len(nodelist), 2)
self.assertEqual(nodelist[0].label, "A container without visible children")

@tag("dh-673")
def test_visible_component_inside_hidden_fieldset_not_skipped(self):
submission = SubmissionFactory.from_components(
[
{
"type": "fieldset",
"key": "fieldset",
"label": "Hidden fieldset",
"hidden": True,
"components": [
{
"type": "textfield",
"key": "textfield",
"label": "Text field",
"hidden": False,
},
],
}
],
)

rendered = render_json(submission)

self.assertEqual(
rendered,
{
submission.steps[0].form_step.slug: {
"fieldset": {
"textfield": "",
},
}
},
)

def test_export_always_emits_all_nodes(self):
renderer = Renderer(self.submission, mode=RenderModes.export, as_html=False)

Expand Down

0 comments on commit f97d322

Please sign in to comment.