From d83b8e2954779042a938adcae444ab3d2ed86746 Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Tue, 29 Oct 2024 09:35:02 +0100 Subject: [PATCH 1/3] :sparkles: [#4546] Ensure the soft required component integrates well * Make sure the HTML for the content is not treated as Django template * Make sure the component is not displayed in summary page/PDF report/ registration data etc. * Added tests --- src/openforms/formio/rendering/default.py | 14 ++++++++++++++ .../rendering/tests/test_component_node.py | 13 +++++++++++-- .../formio/tests/test_variables_injection.py | 18 ++++++++++++++++++ src/openforms/formio/variables.py | 4 ++++ .../tests/test_submission_report.py | 2 ++ 5 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/openforms/formio/rendering/default.py b/src/openforms/formio/rendering/default.py index 8118b7811a..6808a1d334 100644 --- a/src/openforms/formio/rendering/default.py +++ b/src/openforms/formio/rendering/default.py @@ -336,3 +336,17 @@ def label(self) -> str: def render(self) -> str: return f"{self.indent}{self.label}" + + +@register("softRequiredErrors") +class SoftRequiredErrors(ComponentNode): + + @property + def is_visible(self) -> bool: + """ + Mark soft required errors nodes as never visible. + + They are rendered client-side only, so should not show in summaries, PDF, + registration data... + """ + return False diff --git a/src/openforms/formio/rendering/tests/test_component_node.py b/src/openforms/formio/rendering/tests/test_component_node.py index 05051c2595..0cb7f4c9c4 100644 --- a/src/openforms/formio/rendering/tests/test_component_node.py +++ b/src/openforms/formio/rendering/tests/test_component_node.py @@ -11,7 +11,7 @@ from ..structured import render_json -class FormNodeTests(TestCase): +class ComponentNodeTests(TestCase): @classmethod def setUpTestData(cls): super().setUpTestData() @@ -203,6 +203,13 @@ def setUpTestData(cls): }, }, # TODO columns + # soft required validation errors -> always ignored + { + "key": "softRequiredErrors", + "type": "softRequiredErrors", + "html": "

I am hidden

", + "label": "Soft required errors", + }, ] } data = { @@ -451,7 +458,7 @@ def test_render_mode_pdf(self): ) nodelist += list(component_node) - self.assertEqual(len(nodelist), 10) + self.assertEqual(len(nodelist), 11) labels = [node.label for node in nodelist] expected_labels = [ "Input 1", @@ -464,6 +471,7 @@ def test_render_mode_pdf(self): "Input 11", "Visible editgrid with hidden children", "Input 14", + "Soft required errors", # not actually rendered in full render mode ] self.assertEqual(labels, expected_labels) @@ -497,6 +505,7 @@ def test_render_mode_summary(self): "Input 11", "Visible editgrid with hidden children", "Input 14", + "Soft required errors", # not actually rendered in full render mode ] self.assertEqual(labels, expected_labels) diff --git a/src/openforms/formio/tests/test_variables_injection.py b/src/openforms/formio/tests/test_variables_injection.py index db15b8542d..724e0750a1 100644 --- a/src/openforms/formio/tests/test_variables_injection.py +++ b/src/openforms/formio/tests/test_variables_injection.py @@ -184,3 +184,21 @@ def test_rendering_nested_structures(self): result, {"topLevel": {"nested": "yepp"}}, ) + + def test_soft_required_errors_no_server_side_template_evaluation(self): + configuration = { + "components": [ + { + "key": "softRequiredErrors", + "type": "softRequiredErrors", + "html": "

I am hidden

{{ missingFields }}{% now %}", + }, + ] + } + + inject_variables(FormioConfigurationWrapper(configuration), {}) + + self.assertEqual( + configuration["components"][0]["html"], + "

I am hidden

{{ missingFields }}{% now %}", + ) diff --git a/src/openforms/formio/variables.py b/src/openforms/formio/variables.py index 61da96ab2e..b8d1476944 100644 --- a/src/openforms/formio/variables.py +++ b/src/openforms/formio/variables.py @@ -37,6 +37,10 @@ def iter_template_properties(component: Component) -> Iterator[tuple[str, JSONVa Each item returns a tuple with the key and value of the formio component. """ + # no server-side template evaluation here + if component["type"] == "softRequiredErrors": + return + for property_name in SUPPORTED_TEMPLATE_PROPERTIES: property_value = component.get(property_name) yield (property_name, property_value) diff --git a/src/openforms/submissions/tests/test_submission_report.py b/src/openforms/submissions/tests/test_submission_report.py index dc145a2e00..2a80608246 100644 --- a/src/openforms/submissions/tests/test_submission_report.py +++ b/src/openforms/submissions/tests/test_submission_report.py @@ -424,6 +424,8 @@ def test_report_is_generated_in_same_language_as_submission(self): plugins = set(ct for ct, _ in register.items()) # WYSIWIG seems untranslated in SDK TODO after/in issue #2475 plugins.remove("content") + # soft-required errors are not shown in PDF report + plugins.remove("softRequiredErrors") tested_plugins = set(ct for ct, _ in fields if ct in plugins) # add checked structural "layout" components that don't require From c5fc3784475d0dd2ad8615b2b5cef2263029b0dc Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Tue, 29 Oct 2024 09:37:20 +0100 Subject: [PATCH 2/3] :globe_with_meridians: [#4546] Add Formio translations for list label/heading --- src/openforms/js/lang/formio/en.json | 1 + src/openforms/js/lang/formio/nl.json | 1 + 2 files changed, 2 insertions(+) diff --git a/src/openforms/js/lang/formio/en.json b/src/openforms/js/lang/formio/en.json index b32c87960e..2805e38d5a 100644 --- a/src/openforms/js/lang/formio/en.json +++ b/src/openforms/js/lang/formio/en.json @@ -40,5 +40,6 @@ "{{ labels }} or {{ lastLabel }}": "{{ labels }} or {{ lastLabel }}", "invalid_time": "Only times between {{ minTime }} and {{ maxTime }} are allowed.", "You must select at least {{minCount}} items.": "Ensure this field has at least {{minCount}} checked options.", + "Empty fields": "Fields without a value", "": "" } diff --git a/src/openforms/js/lang/formio/nl.json b/src/openforms/js/lang/formio/nl.json index 0c9bfb4dd9..a6c048617e 100644 --- a/src/openforms/js/lang/formio/nl.json +++ b/src/openforms/js/lang/formio/nl.json @@ -408,5 +408,6 @@ "You must verify this email address to continue.": "Om door te gaan moet je dit e-mailadres bevestigen.", "You must select at least {{minCount}} items.": "Zorg dat dit veld {{minCount}} of meer opties aangevinkt heeft.", "Soft required errors": "Foutmeldingen aangeraden velden", + "Empty fields": "Velden zonder antwoord", "": "" } From fc2ffd7222a7a3aca834f1f4631fa0011bf94e07 Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Tue, 29 Oct 2024 09:39:29 +0100 Subject: [PATCH 3/3] :pencil: [#4546] Fix capitalization in docs --- docs/manual/forms/soft_required_fields.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/manual/forms/soft_required_fields.rst b/docs/manual/forms/soft_required_fields.rst index 9b55904fa2..995e53e6f9 100644 --- a/docs/manual/forms/soft_required_fields.rst +++ b/docs/manual/forms/soft_required_fields.rst @@ -18,7 +18,7 @@ ze niet om het formulier in te zenden. Formulierconfiguratie ===================== -.. note:: deze documentatie gaat ervan uit dat je bekend met de basis van +.. note:: Deze documentatie gaat ervan uit dat je bekend met de basis van :ref:`formulieren beheren `. Het is belangrijk dat je in de betreffende formulierstap(pen) een component toevoegt