Skip to content

Commit 51feb1d

Browse files
committed
Add error summary docs
1 parent 873e536 commit 51feb1d

File tree

4 files changed

+103
-5
lines changed

4 files changed

+103
-5
lines changed

content/2.components/character-count.md

Whitespace-only changes.

content/2.components/error-summary.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
layout: component
3+
---
4+
5+
# Error summary
6+
7+
Use this component at the top of a page to summarise any errors a user has made.
8+
9+
When a user makes an error, you must show both an error summary and an [error message](error-message) next to each
10+
answer that contains an error.
11+
12+
See the [GOV.UK Design System documentation on error summaries](https://design-system.service.gov.uk/components/error-summary/)
13+
for more information on when to use this component.
14+
15+
```vue-html
16+
<gv-error-summary :disable-auto-focus="true">
17+
<gv-error-link target-id="name">
18+
Enter your full name
19+
</gv-error-link>
20+
<gv-error-link target-id="passport-date-day">
21+
The date your passport was issued must be in the past
22+
</gv-error-link>
23+
</gv-error-summary>
24+
25+
<gv-input
26+
id="name"
27+
label="Full name"
28+
error-message="Enter your full name"
29+
autocomplete="name"
30+
:spellcheck="false"
31+
/>
32+
33+
<gv-date-input
34+
id="passport-date"
35+
legend="When was your passport issued?"
36+
hint="For example, 27 3 2007"
37+
error-message="The date your passport was issued must be in the past"
38+
:day-has-error="true"
39+
:month-has-error="true"
40+
:year-has-error="true"
41+
/>
42+
```
43+
44+
## Linking to the error
45+
46+
### If the error is for a field on the page
47+
48+
Use the `target-id` prop to specify which field on the page has the error. The page will jump to that field when the error
49+
link is clicked.
50+
51+
You must manually assign an ID to any field which is linked to from the error summary. Do not rely on IDs which GOV.UK Vue
52+
automatically generates, because these may change.
53+
54+
For radios and checkboxes, use the ID of the first radio or checkbox in the list.
55+
56+
For dates, pass an `id` to `gv-date`. The individual fields in the date will use this ID appended with
57+
`-day`, `-month` and -`year` - for example, for `<gv-date id="dob">` the inputs will have IDs of `dob-day`, `dob-month`
58+
and `dob-year`. In the error summary, set the `target-id` to the ID of the field that contains an error. If you don't know
59+
which field has an error, use the ID of the day field.
60+
61+
### If the error is on another page
62+
63+
Use the `href` prop to link to the page with the error.
64+
65+
You can also set up error links to use `router-link` or `nuxt-link` if needed. See
66+
[Using router-link or nuxt-link](/get-started/using-router-link-or-nuxt-link) for more details.
67+
68+
```vue
69+
<script setup lang="ts">
70+
import { NuxtLink } from '#components';
71+
</script>
72+
73+
<template>
74+
<gv-error-summary
75+
title="Some sections are missing information"
76+
:disable-auto-focus="true"
77+
>
78+
<gv-error-link :component="NuxtLink" to="/example-page">
79+
Enter your contact details
80+
</gv-error-link>
81+
</gv-error-summary>
82+
</template>
83+
```
84+
85+
## Using validation libraries
86+
87+
There are several popular validation libraries for Vue, such as [Vuelidate](https://vuelidate-next.netlify.app) and
88+
[VeeValidate](https://vee-validate.logaretm.com). GOV.UK Vue doesn't directly integrate with these libraries, but you should
89+
be able to use this component and the `error-message` prop on form components to integrate them yourself.
90+
91+
If you have any problems integrating with a validation library, [raise an issue on GitHub](https://github.com/govuk-vue/govuk-vue/issues/new).
92+
93+
94+
::gvd-options{component="ErrorSummary" :showName=true}
95+
::
96+
97+
::gvd-options{component="ErrorLink" :showName=true}
98+
::

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"vite-plugin-static-copy": "^0.16.0"
1515
},
1616
"dependencies": {
17-
"govuk-vue": "1.0.0-alpha.5"
17+
"govuk-vue": "1.0.0-alpha.8"
1818
}
1919
}

0 commit comments

Comments
 (0)