Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add guidance for conditional reveal error messages #2012

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions src/components/radios/conditional-reveal-error/index.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
title: Radios with conditionally revealing content showing an error
layout: layout-example.njk
---

{% from "govuk/components/radios/macro.njk" import govukRadios %}
{% from "govuk/components/input/macro.njk" import govukInput %}

{% set emailHtml %}
{{ govukInput({
id: "contact-by-email",
name: "contact-by-email",
type: "email",
autocomplete: "email",
spellcheck: false,
classes: "govuk-!-width-one-half",
label: {
text: "Email address"
},
errorMessage: {
text: "Email address cannot be blank"
}
}) }}
{% endset -%}

{% set phoneHtml %}
{{ govukInput({
id: "contact-by-phone",
name: "contact-by-phone",
type: "tel",
autocomplete: "tel",
classes: "govuk-!-width-one-third",
label: {
text: "Phone number"
}
}) }}
{% endset -%}

{% set textHtml %}
{{ govukInput({
id: "contact-by-text",
name: "contact-by-text",
type: "tel",
autocomplete: "tel",
classes: "govuk-!-width-one-third",
label: {
text: "Mobile phone number"
}
}) }}
{% endset -%}

{{ govukRadios({
idPrefix: "contact",
name: "contact",
fieldset: {
legend: {
text: "How would you prefer to be contacted?",
isPageHeading: true,
classes: "govuk-fieldset__legend--l"
}
},
hint: {
text: "Select one option."
},
items: [
{
value: "email",
text: "Email",
checked: true,
conditional: {
html: emailHtml
}
},
{
value: "phone",
text: "Phone",
conditional: {
html: phoneHtml
}
},
{
value: "text",
text: "Text message",
conditional: {
html: textHtml
}
}
]
}) }}
11 changes: 10 additions & 1 deletion src/components/radios/index.md.njk
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ In services like these, the risk that they will not be noticed is lower because

### Error messages

Display an error message if none of the radios are selected.
Display an error message if the user has not:
EoinShaughnessy marked this conversation as resolved.
Show resolved Hide resolved

- selected any radios
- answered a conditionally revealed question

Error messages should be styled like this:

Expand All @@ -138,6 +141,12 @@ Say ‘Select if [whatever it is]’. For example, ‘Select if you are employed

Say ‘Select [whatever it is]’. For example, ‘Select the day of the week you pay your rent’.

#### If it's a conditionally revealed question

Include an [error message](/components/error-message/) that is clearly related to the initial question.

{{ example({group: "components", item: "radios", example: "conditional-reveal-error", html: true, nunjucks: true, open: false, size: "s"}) }}

## Research on this component

If you’ve done any user research involving conditionally revealed questions, particularly with users of assistive technologies, [tell us what you’ve learned by adding a comment to the discussion about this component](https://github.com/alphagov/govuk-design-system-backlog/issues/59).
Expand Down