Skip to content

Commit

Permalink
Merge pull request #4100 from open-formulieren/issue/input-validation…
Browse files Browse the repository at this point in the history
…-regression

Fix input validation regression for edit grids
  • Loading branch information
sergei-maertens authored Apr 3, 2024
2 parents 3ef4ea6 + 54fbb58 commit fe557fe
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 4 deletions.
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)

# 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

0 comments on commit fe557fe

Please sign in to comment.