Skip to content

Commit

Permalink
Merge pull request #403 from paulwaitehomeoffice/show-hide-content-ch…
Browse files Browse the repository at this point in the history
…aracters-in-name-attribute

Add support to show-hide-content.js for form fields with more varied …
  • Loading branch information
NickColley committed Sep 14, 2018
2 parents 7382de5 + 482309c commit de1a7ff
Show file tree
Hide file tree
Showing 4 changed files with 2,533 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased

- Fix: Add support to show-hide-content.js for form fields with more varied characters: ([PR 403](https://github.com/alphagov/govuk_frontend_toolkit/pull/403))

# 7.6.0

- Strip emails from urls for all GA requests to catch cases when GA generates a new event (e.g. page timings): ([PR 466](https://github.com/alphagov/govuk_frontend_toolkit/pull/466)).
Expand Down
8 changes: 1 addition & 7 deletions javascripts/govuk/show-hide-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
checkbox: '[data-target] > input[type="checkbox"]'
}

// Escape name attribute for use in DOM selector
function escapeElementName (str) {
var result = str.replace('[', '\\[').replace(']', '\\]')
return result
}

// Adds ARIA attributes to control + associated content
function initToggledContent () {
var $control = $(this)
Expand Down Expand Up @@ -79,7 +73,7 @@
// Handle radio show/hide
function handleRadioContent ($control, $content) {
// All radios in this group which control content
var selector = selectors.radio + '[name=' + escapeElementName($control.attr('name')) + '][aria-controls]'
var selector = selectors.radio + '[name="' + $control.attr('name') + '"][aria-controls]'
var $form = $control.closest('form')
var $radios = $form.length ? $form.find(selector) : $(selector)

Expand Down
Loading

0 comments on commit de1a7ff

Please sign in to comment.