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 20, 2025
1 parent 5b20755 commit a6a6937
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
7 changes: 6 additions & 1 deletion src/openforms/formio/formatters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,14 @@ def __call__(self, component: ComponentT, value: Any) -> str:
# note all this depends on value not being unexpected type or shape
values = self.normalise_value_to_list(component, value)

formatted_values = (
formatted_values = list(
force_str(self.format(component, value)) for value in values
)

# Check if formatted_values isn't empty
if len(formatted_values) == 0:
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 a6a6937

Please sign in to comment.