{% macro govukCharacterCount(params) %} {% from "govuk_frontend_jinja/macros/i18n.html" import govukI18nAttributes %} {% from "govuk_frontend_jinja/components/textarea/macro.html" import govukTextarea %} {% from "govuk_frontend_jinja/components/hint/macro.html" import govukHint %} {%- set hasNoLimit = (not params.maxwords and not params.maxlength) -%}
{{ govukTextarea({ 'id': params.id, 'name': params.name, 'describedBy': params.id + '-info', 'rows': params.rows, 'spellcheck': params.spellcheck, 'value': params.value, 'formGroup': params.formGroup, 'classes': 'govuk-js-character-count' + (' ' + params.classes if params.classes else ''), '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 }) }} {%- set textareaDescriptionLength = params.maxwords or params.maxlength %} {%- set textareaDescriptionText = params.textareaDescriptionText or 'You can enter up to %{count} ' + ('words' if params.maxwords else 'characters') %} {#- If the limit is set in JavaScript, we won't be able to interpolate the message until JavaScript, so we only set a text if the `maxlength` or `maxwords` options were provided to the macro. #} {{ govukHint({ 'text': ((textareaDescriptionText) | replace('%{count}', textareaDescriptionLength) if not hasNoLimit), 'id': params.id + '-info', 'classes': 'govuk-character-count__message' + (' ' + params.countMessage.classes if params.countMessage and params.countMessage.classes else '') }) | trim | indent(2) }}
{% endmacro %}