Skip to content

Commit

Permalink
Merge pull request #643 from alphagov/add-error-summary
Browse files Browse the repository at this point in the history
Update GOV.UK Frontend and enable error summary
  • Loading branch information
NickColley authored Nov 19, 2018
2 parents 020805c + f622066 commit f3ca267
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"autoprefixer": "^9.1.0",
"clipboard": "^2.0.1",
"connect": "^3.6.6",
"govuk-frontend": "^2.3.0",
"govuk-frontend": "^2.4.0",
"gray-matter": "^4.0.1",
"highlight.js": "^9.12.0",
"html5shiv": "^3.7.3",
Expand Down
15 changes: 13 additions & 2 deletions src/javascripts/govuk-frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import Button from 'govuk-frontend/components/button/button'
import Details from 'govuk-frontend/components/details/details'
import CharacterCount from 'govuk-frontend/components/character-count/character-count'
import Checkboxes from 'govuk-frontend/components/checkboxes/checkboxes'
// Intentionally avoid importing ErrorSummary since it will steal focus, scrolling example pages.
// import ErrorSummary from 'govuk-frontend/components/error-summary/error-summary'
import ErrorSummary from 'govuk-frontend/components/error-summary/error-summary'
import Radios from 'govuk-frontend/components/radios/radios'
import Header from 'govuk-frontend/components/header/header'
import Tabs from 'govuk-frontend/components/tabs/tabs'
Expand All @@ -15,6 +14,18 @@ if ($details) {
new Details($details).init()
}

var $errorSummary = document.querySelector('[data-module="error-summary"]')
if ($errorSummary) {
var errorSummary = new ErrorSummary($errorSummary)
// Override the `init` method since it automatically focuses the ErrorSummary.
// This is not ideal when showing examples for this component
// TODO: Allow option for ErrorSummary to avoid this hack
errorSummary.init = function () {
this.$module.addEventListener('click', ErrorSummary.prototype.handleClick.bind(this))
}
errorSummary.init()
}

var $characterCount = document.querySelector('[data-module="character-count"]')
if ($characterCount) {
new CharacterCount($characterCount).init()
Expand Down

0 comments on commit f3ca267

Please sign in to comment.