Skip to content

Commit

Permalink
Merge pull request #4801 from open-formulieren/feature/4546-soft-requ…
Browse files Browse the repository at this point in the history
…ired-validation-polish

Polish backend for soft-required validation
  • Loading branch information
sergei-maertens authored Oct 29, 2024
2 parents 4486396 + fc2ffd7 commit 3ae5aad
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/manual/forms/soft_required_fields.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <manual_forms_basics>`.

Het is belangrijk dat je in de betreffende formulierstap(pen) een component toevoegt
Expand Down
14 changes: 14 additions & 0 deletions src/openforms/formio/rendering/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 11 additions & 2 deletions src/openforms/formio/rendering/tests/test_component_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ..structured import render_json


class FormNodeTests(TestCase):
class ComponentNodeTests(TestCase):
@classmethod
def setUpTestData(cls):
super().setUpTestData()
Expand Down Expand Up @@ -203,6 +203,13 @@ def setUpTestData(cls):
},
},
# TODO columns
# soft required validation errors -> always ignored
{
"key": "softRequiredErrors",
"type": "softRequiredErrors",
"html": "<p>I am hidden</p>",
"label": "Soft required errors",
},
]
}
data = {
Expand Down Expand Up @@ -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",
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
18 changes: 18 additions & 0 deletions src/openforms/formio/tests/test_variables_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<p>I am hidden</p>{{ missingFields }}{% now %}",
},
]
}

inject_variables(FormioConfigurationWrapper(configuration), {})

self.assertEqual(
configuration["components"][0]["html"],
"<p>I am hidden</p>{{ missingFields }}{% now %}",
)
4 changes: 4 additions & 0 deletions src/openforms/formio/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/openforms/js/lang/formio/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"": ""
}
1 change: 1 addition & 0 deletions src/openforms/js/lang/formio/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
"": ""
}
2 changes: 2 additions & 0 deletions src/openforms/submissions/tests/test_submission_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3ae5aad

Please sign in to comment.