Create a check answers page
It’s helpful to let users check their answers before submitting them. To do this, we’ll add a check answers page.
Create an empty file named check-your-answers.html in app/views.
Add this line to the top of the file:
Copy the Nunjucks code from the check answers pattern page and add it to the file.
Go to http://localhost:3000/check-your-answers to check it works.
Show the user’s answers
The prototype kit stores answers that users enter. This means you can make more realistic prototypes, for example by showing answers for users to check or to branch off to different pages depending on their answer.
When storing data, the kit uses the name attribute from the component to save it. We’ll use this when looking up the user’s answer.
Show the answer to question 1
- Open
check-your-answers.htmlin yourapp/viewsfolder. - In the first row, find the
keythat contains the text “NHS number”. - Change “NHS number” to “Symptoms of magical powers”.
- In
valueon the next line, change ‘485 777 3456’ todata.hasSymptoms.
This is how we use data a user has entered – ‘hasSymptoms’ is the name attribute from the input component on the question page.
In the same row, find the line with visuallyHiddenText and change ‘NHS number’ to ‘symptoms of magical powers’.
The link text will read as “Change symptoms of magical powers” to screen reader users. Screen readers will read this out but it will not appear on the page. Without this hidden text, screen reader users would just hear “Change” and not necessarily know what it relates to.
Show the answer to question 2
- In the second row, find the
keythat contains the text ‘Name’. - Change “Name” to “Details of the symptoms”.
- In the
valueon the next line, change ‘Kevin Francis’ todata.details. - On the line with
visuallyHiddenText, change ‘name’ to ‘details of the symptoms’
Go to http://localhost:3000/ and answer the questions to check your answers show up correctly.
Delete the remaining example answers
In the code there are some example answers that you do not need.
- Find the
,(comma) after the details you have changed, and delete this and everything up to the](square bracket). - Delete everything from the line that contains “Medical details” down to the line before “Now send your application”.
Your code should now look like this:
You can edit the “Now send your application” heading and the content after it to make it more suitable for this service.
Link up the pages
As before, you’ll need to link up this page with previous pages.
Make the ‘Change’ links work
Unlike the previous question pages, there is no back link on the check answers pattern as instead users can go back to any previous question page using the change links in the summary.
Make the change links on the page work by adding the right links.
- Find the row for
Symptoms of magical powers, then change thehrefvalue from"#"to"/magical-powers" - Find the row for
Details of the symptoms, then change thehrefvalue from"#"to"/details"
Link to check answers page from the last question
We also need to link the last question page to the check answers page.
To do this:
- Open
details.htmlin yourapp/viewsfolder. - Find the line
<form action="/form-handler" method="post" novalidate>. - Change the value of the
actionattribute from/form-handlerto/check-your-answers.
Click on the continue button to check that it now works. It should take you the second question page.