Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polish backend for soft-required validation #4801

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/installation/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ Other settings

.. _django-sendfile documentation: https://django-sendfile2.readthedocs.io/en/stable/backends.html

.. _`Django DATABASE settings`: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-DATABASE-ENGINE
.. _`Django DATABASE settings`: https://docs.djangoproject.com/en/4.2/ref/settings/#engine

.. _installation_environment_config_feature_flags:

Expand Down
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
Loading