diff --git a/app/assets/javascripts/components/expander.js b/app/assets/javascripts/components/expander.js index 7a2812131..b7befeb53 100644 --- a/app/assets/javascripts/components/expander.js +++ b/app/assets/javascripts/components/expander.js @@ -74,7 +74,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {}; // if this ; is omitted, none try { buttonAttributes = JSON.parse(buttonAttributes) for (var rawKey in buttonAttributes) { - var key = rawKey.replace(/_/i, '-').toLowerCase() + var key = rawKey.replace(/_/g, '-').toLowerCase() var rawValue = buttonAttributes[rawKey] var value = typeof rawValue === 'object' ? JSON.stringify(rawValue) : rawValue $button.setAttribute('data-' + key, value) diff --git a/spec/javascripts/components/expander-spec.js b/spec/javascripts/components/expander-spec.js index 044e38415..16060d543 100644 --- a/spec/javascripts/components/expander-spec.js +++ b/spec/javascripts/components/expander-spec.js @@ -131,7 +131,8 @@ describe('An expander module', function () { ga4_expandable: '', ga4_event: { event_name: 'select_content', - type: 'finder' + type: 'finder', + test_attribute_with_many_underscores: 'oh yes' } }