Skip to content

Commit

Permalink
🐛 [#4126] Conditions may refer to form fields outside the editgrid
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Apr 8, 2024
1 parent 5d5fe5d commit e51f543
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/openforms/formio/components/vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def run_child_validation(self, data):
# configuration and apply the dynamic hide/visible logic to it.
# Note that we add the editgrid key as container so that the
# conditional.when values resolve, as these look like `editgridparent.child`.
data = FormioData({self.field_name: item}).data
data = FormioData({**self.root.initial_data, self.field_name: item}).data
nested_serializer = self._build_child(data=data)
try:
result.append(nested_serializer.run_validation(item))
Expand Down
58 changes: 58 additions & 0 deletions src/openforms/formio/tests/validation/test_editgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,64 @@ def test_conditional_hidden_inside_editgrid(self):

self.assertTrue(is_valid)

@tag("dh-673")
def test_conditional_hidden_inside_editgrid_with_reference_to_outside_editgrid(
self,
):
editgrid: EditGridComponent = {
"type": "editgrid",
"key": "editgrid",
"label": "Edit grid with nested conditional",
"components": [
{
"type": "textfield",
"key": "nestedInEditgrid",
"label": "Nested in edit grid",
"validate": {"required": True},
"conditional": { # type: ignore
"eq": "SHOW_NESTED",
"show": True,
"when": "outsideEditgrid",
},
},
],
}
component: FieldsetComponent = {
"type": "fieldset",
"key": "fieldset",
"label": "Container",
"components": [
{
"type": "textfield",
"key": "outsideEditgrid",
"label": "Textfield outside edit grid",
},
editgrid,
],
}

with self.subTest("invalid"):
invalid_data: JSONValue = {
"outsideEditgrid": "SHOW_NESTED",
"editgrid": [{}],
}

is_valid, errors = validate_formio_data(component, invalid_data)

self.assertFalse(is_valid)
error = extract_error(errors["editgrid"][0], "nestedInEditgrid")
self.assertEqual(error.code, "required")

with self.subTest("valid"):
invalid_data: JSONValue = {
"outsideEditgrid": "NO_SHOW_NESTED",
"editgrid": [{}],
}

is_valid, errors = validate_formio_data(component, invalid_data)

self.assertTrue(is_valid)


class EditGridFieldTests(SimpleTestCase):
"""
Expand Down

0 comments on commit e51f543

Please sign in to comment.