Skip to content

Commit

Permalink
♿ [#5047] Show "not filled in" when a field is empty in the submissio…
Browse files Browse the repository at this point in the history
…n report pdf

To indicate when a field has been left empty by the user, show "No information provided" in the place where the filled in information would have been.
This also helps screen reader users identify which fields aren't filled in.
  • Loading branch information
robinmolen committed Feb 11, 2025
1 parent 66d0986 commit 6359964
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/openforms/formio/formatters/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from dataclasses import dataclass
from itertools import tee
from typing import Any, Generic, Iterable, Sequence, TypeVar

from django.utils.encoding import force_str
Expand Down Expand Up @@ -73,6 +74,15 @@ def __call__(self, component: ComponentT, value: Any) -> str:
formatted_values = (
force_str(self.format(component, value)) for value in values
)

# Check if formatted_values isn't empty
formatted_values_copy, formatted_values = tee(formatted_values)
try:
next(formatted_values_copy) # Try to get the first item
except StopIteration:
# If formatted_values is empty, return an empty string
return self.process_result(component, "")

# logically we'd want a .filter_formatted_values() step here
return self.process_result(
component, self.join_formatted_values(component, formatted_values)
Expand Down
18 changes: 11 additions & 7 deletions src/openforms/formio/formatters/formio.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,17 @@ def format(self, component: SelectBoxesComponent, value: dict[str, bool]) -> str
# For the html output, wrap the values in li tags and put it inside an ul tag.
# The selectboxes formatter handles all values at the same time,
# so handle the full html formatting here.
return format_html(
"<ul>{values}</ul>",
values=format_html_join(
"",
"<li>{}</li>",
((selected_label,) for selected_label in selected_labels),
),
return (
format_html(
"<ul>{values}</ul>",
values=format_html_join(
"",
"<li>{}</li>",
((selected_label,) for selected_label in selected_labels),
),
)
if len(selected_labels) > 0
else ""
)
return self.multiple_separator.join(selected_labels)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ <h2 class="subtitle">{{ submission_step_node.render }}</h2>
</span>

<div aria-labelledby="{{ component_node.key }}" class="submission-step-row__value{% if not component_node.display_value %} submission-step-row__value--empty{% endif %}">
{{ component_node.display_value|default:"" }}
{% if component_node.display_value %}
{{ component_node.display_value }}
{% else %}
{% trans "No information provided" %}
{% endif %}
</div>
{% endif %}
{% endif %}
Expand Down

0 comments on commit 6359964

Please sign in to comment.