Skip to content

Commit

Permalink
Use Character count formGroup as module wrapper
Browse files Browse the repository at this point in the history
This removes the wrapping data-module `<div>` and puts all attributes on the Textarea `formGroup` instead
  • Loading branch information
colinrotherham committed Jan 10, 2024
1 parent 341017b commit 3292e8d
Showing 1 changed file with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
Unlike objects which cannot be modified, Nunjucks can both push to and loop
arrays (as if they were objects) when in `Object.entries()` array format
#}
{%- set attributes = [] -%}
{%- set attributes = [
["data-module", "govuk-character-count"]
] -%}

{% for attribute, value in params.formGroup.attributes %}
{% set attributes = (attributes.push([attribute, value]), attributes) %}
Expand Down Expand Up @@ -76,30 +78,28 @@
}) }}
{% endset -%}

<div class="govuk-character-count" data-module="govuk-character-count">
{{ govukTextarea({
id: params.id,
name: params.name,
describedBy: params.id + '-info',
rows: params.rows,
spellcheck: params.spellcheck,
value: params.value,
formGroup: {
classes: params.formGroup.classes,
attributes: attributes,
afterHtml: countMessageHtml
},
classes: 'govuk-js-character-count' + (' ' + params.classes if params.classes),
label: {
html: params.label.html,
text: params.label.text,
classes: params.label.classes,
isPageHeading: params.label.isPageHeading,
attributes: params.label.attributes,
for: params.id
},
hint: params.hint,
errorMessage: params.errorMessage,
attributes: params.attributes
}) }}
</div>
{{ govukTextarea({
id: params.id,
name: params.name,
describedBy: params.id + '-info',
rows: params.rows,
spellcheck: params.spellcheck,
value: params.value,
formGroup: {
classes: 'govuk-character-count' + (' ' + params.formGroup.classes if params.formGroup.classes),
attributes: attributes,
afterHtml: countMessageHtml
},
classes: 'govuk-js-character-count' + (' ' + params.classes if params.classes),
label: {
html: params.label.html,
text: params.label.text,
classes: params.label.classes,
isPageHeading: params.label.isPageHeading,
attributes: params.label.attributes,
for: params.id
},
hint: params.hint,
errorMessage: params.errorMessage,
attributes: params.attributes
}) }}

0 comments on commit 3292e8d

Please sign in to comment.