From d57a940b650e27b8b492ca04e916fb42a9c901ac Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Thu, 14 Mar 2024 17:01:49 +0100 Subject: [PATCH 1/2] :sparkles: [#3977] Add submission context to formio data serializer So that the plugin validators can run in the context of the provided submission and not crash. --- src/openforms/submissions/api/validation.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/openforms/submissions/api/validation.py b/src/openforms/submissions/api/validation.py index 3c5775e625..5e53c64c61 100644 --- a/src/openforms/submissions/api/validation.py +++ b/src/openforms/submissions/api/validation.py @@ -57,7 +57,11 @@ def validate(self, attrs: dict): assert step.form_step components = step.form_step.form_definition.configuration["components"] - step_data_serializer = build_serializer(components, data=data) + step_data_serializer = build_serializer( + components, + data=data, + context={"submission": submission}, + ) if not step_data_serializer.is_valid(): errors = step_data_serializer.errors From b4ccdb26e91121f221909ce833b1e4ad24618c6a Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Fri, 15 Mar 2024 15:51:09 +0100 Subject: [PATCH 2/2] :white_check_mark: [#3977] Add end-to-end test for textfield plugin validation This ensures that the plugin validators are correctly wired up. --- src/openforms/tests/e2e/test_input_validation.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/openforms/tests/e2e/test_input_validation.py b/src/openforms/tests/e2e/test_input_validation.py index 2f83e5f85c..2e13f708b6 100644 --- a/src/openforms/tests/e2e/test_input_validation.py +++ b/src/openforms/tests/e2e/test_input_validation.py @@ -80,6 +80,22 @@ def test_regex_house_number_addition(self): expected_ui_error="Huisnummertoevoeging mag enkel alfanumerieke karaketers zijn.", ) + def test_kvk_number_validation_plugin(self): + component: Component = { + "type": "textfield", + "key": "chamberOfCommerce", + "label": "KVK nummer", + "validate": { + "plugins": ["kvk-kvkNumber"], + }, + } + + self.assertValidationIsAligned( + component, + ui_input="aaaa", # deliberate to trigger the non-network validation + expected_ui_error="Waarde moet numeriek zijn.", + ) + class SingleEmailTests(ValidationsTestCase): def test_required_field(self):