Skip to content

Commit

Permalink
Render error summary on cya (in case a developer overrides the statem…
Browse files Browse the repository at this point in the history
…ent of truth)
  • Loading branch information
michaeldfallen committed Jan 12, 2018
1 parent bd5c8c3 commit cb0980c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
14 changes: 14 additions & 0 deletions templates/look-and-feel/components/errors.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% macro errorSummary(fields, title='There was a problem') -%}
{%- if fields.validated and not fields.valid -%}
<div class="error-summary" role="group" aria-labelledby="error-summary-heading" tabindex="-1">
<h1 class="heading-medium error-summary-heading" id="error-summary-heading">
{{ title }}
</h1>
<ul class="error-summary-list">
{%- for error in fields.errors -%}
<li><a href="#{{error.id}}">{{error.message}}</a></li>
{%- endfor -%}
</ul>
</div>
{%- endif -%}
{%- endmacro %}
3 changes: 3 additions & 0 deletions templates/look-and-feel/layouts/check_your_answers.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% from "look-and-feel/components/check-your-answers.njk" import answer %}
{% from "look-and-feel/components/phase_banner.njk" import phaseBanner %}
{% from "look-and-feel/components/fields.njk" import hiddenInput %}
{% from "look-and-feel/components/errors.njk" import errorSummary %}

{% set defaultContent = {
title: 'Check your answers',
Expand All @@ -24,6 +25,8 @@

{{ header(pageContent.title | default(defaultContent.title)) }}

{{ errorSummary(fields) }}

{% for section in _sections %}

{% if section.atLeast1Completed %}
Expand Down
14 changes: 2 additions & 12 deletions templates/look-and-feel/layouts/question.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "look-and-feel/layouts/two_thirds.html" %}
{% from "look-and-feel/components/header.njk" import header %}
{% from "look-and-feel/components/phase_banner.njk" import phaseBanner %}
{% from "look-and-feel/components/errors.njk" import errorSummary %}

{% block page_title %}{{ title }}{% endblock %}

Expand All @@ -15,18 +16,7 @@

<form action="{{ postUrl | default(path if path else url) }}" method="post" class="form">

{%- if fields.validated and not fields.valid -%}
<div class="error-summary" role="group" aria-labelledby="error-summary-heading" tabindex="-1">
<h1 class="heading-medium error-summary-heading" id="error-summary-heading">
There was a problem
</h1>
<ul class="error-summary-list">
{%- for error in fields.errors -%}
<li><a href="#{{error.id}}">{{error.message}}</a></li>
{%- endfor -%}
</ul>
</div>
{%- endif -%}
{{ errorSummary(fields) }}

{% block fields -%}
{%- endblock %}
Expand Down

0 comments on commit cb0980c

Please sign in to comment.