Skip to content

Commit

Permalink
Make it possible to set the error state on checkboxes without passing…
Browse files Browse the repository at this point in the history
… an error message

Currently the error state for a conditionally revealed content shows the 'error bar' against the revealed content only.

We want to move the error bar to the 'question' which will include the revealing checkboxes themselves.
  • Loading branch information
igloosi committed Oct 30, 2018
1 parent 567a09f commit 2080e92
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/components/checkboxes/checkboxes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ params:
required: false
description: Options for the errorMessage component (e.g. text).
isComponent: true
- name: formGroup
type: object
required: false
description: Options for the form-group wrapper
params:
- name: classes
type: string
required: false
description: Optional classes to add to the form group (e.g. to show error state for the whole group)
- name: idPrefix
type: string
required: false
Expand Down Expand Up @@ -343,3 +352,34 @@ examples:
html: |
<label class="govuk-label" for="contact-text-message">Mobile phone number</label>
<input class="govuk-input govuk-!-width-one-third" name="contact-text-message" type="text" id="contact-text-message">
- name: with optional form-group classes showing group error
readme: false
data:
idPrefix: how-contacted-checked
formGroup:
classes: 'govuk-form-group--error'
fieldset:
legend:
text: How do you want to be contacted?
items:
- value: email
text: Email
conditional:
html: |
<label class="govuk-label" for="context-email">Mobile phone number</label>
<input class="govuk-input govuk-!-width-one-third" name="context-email" type="text" id="context-email">
- value: phone
text: Phone
checked: true
conditional:
html: |
<label class="govuk-label" for="contact-phone">Phone number</label>
<span id="contact-phone-error" class="govuk-error-message">Problem with input</span>
<input class="govuk-input govuk-input--error govuk-!-width-one-third" name="contact-phone" type="text" id="contact-phone" aria-describedby="contact-phone-error">
- value: text
text: Text message
conditional:
html: |
<label class="govuk-label" for="contact-text-message">Mobile phone number</label>
<input class="govuk-input govuk-!-width-one-third" name="contact-text-message" type="text" id="contact-text-message">
2 changes: 1 addition & 1 deletion src/components/checkboxes/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</div>
{% endset -%}

<div class="govuk-form-group {%- if params.errorMessage %} govuk-form-group--error{% endif %}">
<div class="govuk-form-group {%- if params.errorMessage %} govuk-form-group--error{% endif %} {%- if params.formGroup.classes %} {{ params.formGroup.classes }}{% endif %}">
{% if params.fieldset %}
{% call govukFieldset({
describedBy: describedBy,
Expand Down
22 changes: 22 additions & 0 deletions src/components/checkboxes/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,28 @@ describe('Checkboxes', () => {
expect($formGroup.length).toBeTruthy()
})

it('render a custom class on the form group', () => {
const $ = render('checkboxes', {
name: 'example-name',
items: [
{
value: '1',
text: 'Option 1'
},
{
value: '2',
text: 'Option 2'
}
],
formGroup: {
classes: 'custom-group-class'
}
})

const $formGroup = $('.govuk-form-group')
expect($formGroup.hasClass('custom-group-class')).toBeTruthy()
})

describe('items', () => {
it('render a matching label and input using name by default', () => {
const $ = render('checkboxes', {
Expand Down

0 comments on commit 2080e92

Please sign in to comment.