Skip to content

Commit

Permalink
Merge pull request #603 from nhsuk/feature/173-conditional-inputs
Browse files Browse the repository at this point in the history
Conditional content for radios and checkboxes
  • Loading branch information
davidhunter08 authored Apr 23, 2020
2 parents d2d9eab + 5cc437a commit 4a8edd4
Show file tree
Hide file tree
Showing 35 changed files with 2,133 additions and 3,261 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# NHS.UK frontend Changelog

## 3.1.0 - TBC

:new: **New features**

- Checkboxes with conditional content - add functionality to show and hide conditional content when checkbox is checked
- Radios with conditional content - add functionality to show and hide conditional content when radio is checked
- JS utils - add addClass, removeClass, getClasses and hasClass utils

:wrench: **Fixes**

- Tidy dependencies - Removed unnecessary JavaScript linting NPM packages
- JS utils - Fix toggleClass util which duplicated classes if there was no other class before it, more tests added
- Nunjucks documentation - describe items as arrays not objects ([Issue 604](https://github.com/nhsuk/nhsuk-frontend/issues/604))

## 3.0.4 - 24 March 2020

:wrench: **Fixes**
Expand Down
90 changes: 90 additions & 0 deletions app/components/checkboxes/conditional.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{% set html_style = 'background-color: #f0f4f5;' %}
{% set title = 'Checkboxes with conditional content' %}
{% from 'components/checkboxes/macro.njk' import checkboxes %}
{% from 'components/input/macro.njk' import input %}
{% extends 'layout.njk' %}

{% set emailHtml %}
{{ input({
id: "email",
name: "email",
classes: "nhsuk-u-width-two-thirds",
label: {
text: "Email address"
}
}) }}
{% endset -%}

{% set phoneHtml %}
{{ input({
id: "phone",
name: "phone",
classes: "nhsuk-u-width-two-thirds",
label: {
text: "Phone number"
}
}) }}
{% endset -%}

{% set mobileHtml %}
{{ input({
id: "mobile",
name: "mobile",
classes: "nhsuk-u-width-two-thirds",
label: {
text: "Mobile phone number"
}
}) }}
{% endset -%}

{% block body %}

<div class="nhsuk-width-container">
<main class="nhsuk-main-wrapper" id="maincontent">

<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-two-thirds">
{{ checkboxes({
"idPrefix": "contact",
"name": "contact",
"fieldset": {
"legend": {
"text": "How would you prefer to be contacted?",
"classes": "nhsuk-fieldset__legend--l",
"isPageHeading": "true"
}
},
"hint": {
"text": "Select all options that are relevant to you."
},
"items": [
{
"value": "email",
"text": "Email",
"conditional": {
"html": emailHtml
}
},
{
"value": "phone",
"text": "Phone",
"conditional": {
"html": phoneHtml
}
},
{
"value": "text",
"text": "Text message",
"conditional": {
"html": mobileHtml
}
}
]
}) }}
</div>
</div>

</main>
</div>

{% endblock %}
90 changes: 90 additions & 0 deletions app/components/radios/conditional.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{% set html_style = 'background-color: #f0f4f5;' %}
{% set title = 'Radios with conditonal content' %}
{% from 'components/radios/macro.njk' import radios %}
{% from 'components/input/macro.njk' import input %}
{% extends 'layout.njk' %}

{% set emailHtml %}
{{ input({
id: "email",
name: "email",
classes: "nhsuk-u-width-two-thirds",
label: {
text: "Email address"
}
}) }}
{% endset -%}

{% set phoneHtml %}
{{ input({
id: "phone",
name: "phone",
classes: "nhsuk-u-width-two-thirds",
label: {
text: "Phone number"
}
}) }}
{% endset -%}

{% set mobileHtml %}
{{ input({
id: "mobile",
name: "mobile",
classes: "nhsuk-u-width-two-thirds",
label: {
text: "Mobile phone number"
}
}) }}
{% endset -%}

{% block body %}

<div class="nhsuk-width-container">
<main class="nhsuk-main-wrapper" id="maincontent">

<div class="nhsuk-grid-row">
<div class="nhsuk-grid-column-two-thirds">
{{ radios({
"idPrefix": "contact",
"name": "contact",
"fieldset": {
"legend": {
"text": "How would you prefer to be contacted?",
"classes": "nhsuk-fieldset__legend--l",
"isPageHeading": "true"
}
},
"hint": {
"text": "Select one option."
},
"items": [
{
"value": "email",
"text": "Email",
"conditional": {
"html": emailHtml
}
},
{
"value": "phone",
"text": "Phone",
"conditional": {
"html": phoneHtml
}
},
{
"value": "text",
"text": "Text message",
"conditional": {
"html": mobileHtml
}
}
]
}) }}
</div>
</div>

</main>
</div>

{% endblock %}
2 changes: 2 additions & 0 deletions app/pages/examples.njk
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<li><a href="../components/checkboxes/disabled.html">Checkboxes with disabled item</a></li>
<li><a href="../components/checkboxes/page-heading.html">Checkboxes with legend as page heading</a></li>
<li><a href="../components/checkboxes/error.html">Checkboxes with error message</a></li>
<li><a href="../components/checkboxes/conditional.html">Checkboxes with conditional content</a></li>
<li><a href="../components/contents-list/index.html">Contents list</a></li>
<li><a href="../components/date-input/index.html">Date input</a></li>
<li><a href="../components/date-input/autocomplete.html">Date input with autocomplete attribute</a></li>
Expand Down Expand Up @@ -92,6 +93,7 @@
<li><a href="../components/radios/hint.html">Radios with hint text</a></li>
<li><a href="../components/radios/without-fieldset.html">Radios without fieldset</a></li>
<li><a href="../components/radios/hint-error.html">Radios with hint text and error message</a></li>
<li><a href="../components/radios/conditional.html">Radios with conditional content</a></li>
<li><a href="../components/review-date/index.html">Review date</a></li>
<li><a href="../components/select/index.html">Select</a></li>
<li><a href="../components/select/hint-error.html">Select with hint text and error message</a></li>
Expand Down
Loading

0 comments on commit 4a8edd4

Please sign in to comment.