Show error across the whole row

Errors with messages being too long or empty aren’t specific to a single
cell of the uploaded spreadsheet, they’re the results of combining all
the cells with the template.

Previously we could only show errors against a specific cell. This
commit makes it possible to add a super-row which spans all the cells,
into which we can put errors.

The index (header) column then spans both these rows, to show that they
are both associated with the same row of input.

Depends on:
- [x] https://github.com/alphagov/notifications-utils/pull/719
This commit is contained in:
Chris Hill-Scott
2020-04-11 11:42:13 +01:00
parent f37137cdb3
commit e2d1401b54
3 changed files with 38 additions and 10 deletions

View File

@@ -65,12 +65,12 @@
{% endif %}
{%- endmacro %}
{% macro field(align='left', status='', border=True) -%}
{% macro field(align='left', status='', border=True, colspan=None) -%}
{% set field_alignment = 'table-field-right-aligned' if align == 'right' else 'table-field-left-aligned' %}
{% set border = '' if border else 'table-field-noborder' %}
<td class="{{ [field_alignment, border]|join(' ') }}">
<td class="{{ [field_alignment, border]|join(' ') }}" {% if colspan %}colspan="{{ colspan }}"{% endif %}>
<div class="{{ 'table-field-status-' + status if status }}">{{ caller() }}</div>
</td>
{%- endmacro %}
@@ -81,8 +81,8 @@
</th>
{%- endmacro %}
{% macro index_field(text=None) -%}
<td class="table-field-index">
{% macro index_field(text=None, rowspan=None) -%}
<td class="table-field-index" {% if rowspan %}rowspan="{{ rowspan }}"{% endif %}>
{{ text if text != None else caller() }}
</td>
{%- endmacro %}

View File

@@ -67,12 +67,32 @@
] + recipients.column_headers
) %}
{% for item in recipients.displayed_rows %}
{% call row(item.id) %}
{% call index_field() %}
<span class="{% if item.has_errors %}table-field-error{% endif %}">
{{ item.index + 2 }}
</span>
{% if item.has_error_spanning_multiple_cells %}
{% call row() %}
{% call index_field(rowspan=2) %}
<span class="table-field-error">
{{ item.index + 2 }}
</span>
{% endcall %}
{% call field(colspan=recipients.column_headers|length) %}
<span class="table-field-error-label">
{% if item.message_empty %}
No content for this message
{% elif item.message_too_long %}
Message is too long
{% endif %}
</span>
{% endcall %}
{% endcall %}
{% endif %}
{% call row(item.id) %}
{% if not item.has_error_spanning_multiple_cells %}
{% call index_field() %}
<span class="{% if item.has_errors %}table-field-error{% endif %}">
{{ item.index + 2 }}
</span>
{% endcall %}
{% endif %}
{% for column in recipients.column_headers %}
{% if item[column].error and not recipients.missing_column_headers %}
{% call field() %}