Skip to content
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

Fix input validation regression for edit grids #4100

Merged
merged 2 commits into from
Apr 3, 2024
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
4 changes: 2 additions & 2 deletions src/openforms/formio/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ def apply_hidden_state(
Hidden fields in Formio don't run *any* validation, see the
``Component.shouldSkipValidation`` method for reference.
"""
config_wrapper = FormioConfigurationWrapper(configuration)

# initial_data is only set if Serializer(data=...) was used, and we can't take
# (dynamic) hidden state into account without initial data.
if not hasattr(self, "initial_data"):
return

config_wrapper = FormioConfigurationWrapper(configuration)

sergei-maertens marked this conversation as resolved.
Show resolved Hide resolved
# can't use FormioData yet because of is_visible_in_frontend
values: DataMapping = self.initial_data

Expand Down
78 changes: 78 additions & 0 deletions src/openforms/formio/tests/validation/test_editgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,81 @@ def test_required_but_empty_editgrid(self):
)

self.assertTrue(is_valid)

@tag("dh-667")
def test_regression_dh_ooievaarspas(self):
# Some fields inside the repeating group apparently get/got hoisted to the
# root serializer.
components = [
{
"type": "content",
"key": "werkgeverInfo",
"label": "werkgeverInfo",
"html": "<p>Als u een werkgever heeft krijgt u loon. Dit noemen we ook wel inkomen. U bent dan in loondienst.</p>",
},
{
"type": "radio",
"key": "heeftUEenWerkgever",
"label": "Heeft u een werkgever?",
"validate": {"required": True},
"openForms": {"dataSrc": "manual"},
"values": [
{"label": "Ja", "value": "ja"},
{"label": "Nee", "value": "nee"},
],
},
{
"type": "fieldset",
"key": "loondienstWerkgevers",
"label": "Loondienst/werkgever(s)",
"conditional": {"eq": "ja", "show": True, "when": "heeftUEenWerkgever"},
"components": [
{
"type": "editgrid",
"key": "werkgevers",
"label": "Werkgever(s)",
"groupLabel": "Werkgever",
"validate": {"maxLength": 4},
"components": [
{
"type": "textfield",
"key": "naamWerkgever",
"label": "Naam werkgever",
"validate": {"required": True},
},
{
"type": "currency",
"key": "nettoLoon",
"label": "Hoeveel nettoloon krijgt u ?",
"currency": "EUR",
"validate": {"required": True},
},
{
"type": "radio",
"key": "periodeNettoLoon",
"label": "Over welke periode ontvangt u dit loon?",
"validate": {"required": True},
"openForms": {"dataSrc": "manual"},
"values": [
{"label": "Per week", "value": "week"},
{"label": "Per 4 weken", "value": "vierWeken"},
{"label": "Per maand", "value": "maand"},
],
},
],
}
],
},
]
data = {
"heeftUEenWerkgever": "ja",
"werkgevers": [
{"naamWerkgever": "ABC", "nettoLoon": 5, "periodeNettoLoon": "maand"}
],
}
context = {"submission": SubmissionFactory.build()}
serializer = build_serializer(components=components, data=data, context=context)

is_valid = serializer.is_valid()

self.assertTrue(is_valid)
10 changes: 8 additions & 2 deletions src/openforms/formio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def iter_components(
assert not components, "Both nested components and columns found"
for column in configuration["columns"]:
yield from iter_components(
configuration=column, recursive=recursive, _is_root=False
configuration=column,
recursive=recursive,
_is_root=False,
recurse_into_editgrid=recurse_into_editgrid,
)

for component in components:
Expand All @@ -52,7 +55,10 @@ def iter_components(
if component.get("type") == "editgrid" and not recurse_into_editgrid:
continue
yield from iter_components(
configuration=component, recursive=recursive, _is_root=False
configuration=component,
recursive=recursive,
_is_root=False,
recurse_into_editgrid=recurse_into_editgrid,
)


Expand Down
Loading