Character count Nunjucks macro options
Use options to customise the appearance, content and behaviour of this component when using a macro, for example, changing the text.
Also see the guidance on the Character count component page, which shows these options in use within each example.
Some options are required for the macro to work; these are marked as "Required" in the option description. Deprecated options are marked as "Deprecated".
If you're using Nunjucks macros in production with "html" options, or ones ending with "html", you must sanitise the HTML to protect against cross-site scripting exploits.
| Name | Type | Description |
|---|---|---|
| id | string |
The ID of the textarea. Defaults to the value of name.
|
| name | string | Required. The name of the textarea, which is submitted with the form data. |
| rows | string | Optional number of textarea rows (default is 5 rows). |
| value | string | Optional initial value of the textarea. |
| maxlength | string |
Required.
The maximum number of characters (or words if countType is set to "words").
|
| maxwords | string |
Deprecated in 6.6.0 Required. The maximum number of words. Replaced by the maxlength and countType: "words" options.
|
| threshold | string | The percentage value of the limit at which point the count message is displayed. If this attribute is set, the count message will be hidden by default. |
| count |
string |
The count type used to count the text – "length" or "words". Defaults to "length".
|
| label | object | Required. The label used by the character count component. See macro options for label. |
| hint | object | Can be used to add a hint to the character count component. See macro options for hint. |
| error |
object |
Can be used to add an error message to the character count component. The error message component will not display if you use a falsy value for errorMessage, for example false or null.
See macro options for error |
| form |
object |
Additional options for the form group containing the character count component.
See macro options for form |
| classes | string | Classes to add to the textarea. |
| attributes | object | HTML attributes (for example data attributes) to add to the textarea. |
| spellcheck | boolean |
Optional field to enable or disable the spellcheck attribute on the character count.
|
| count |
object |
Additional options for the count message used by the character count component.
See macro options for count |
| textarea |
string |
Message made available to assistive technologies to describe that the component accepts only a limited amount of content. It is visible on the page if countType is not supported or JavaScript is unavailable. The component will replace the %{count} placeholder with the value of the maxlength parameter.
|
| characters |
object |
Message displayed when the number of characters is under the configured maximum, maxlength. This message is displayed visually and through assistive technologies. The component will replace the %{count} placeholder with the number of remaining characters. Our pluralisation rules apply to this macro option.
|
| characters |
string |
Message displayed when the number of characters reaches the configured maximum, maxlength. This message is displayed visually and through assistive technologies.
|
| characters |
object |
Message displayed when the number of characters is over the configured maximum, maxlength. This message is displayed visually and through assistive technologies. The component will replace the %{count} placeholder with the number of characters above the maximum.Our pluralisation rules apply to this macro option.
|
| words |
object |
Message displayed when the number of words is under the configured maximum, maxlength with countType: "words". This message is displayed visually and through assistive technologies. The component will replace the %{count} placeholder with the number of remaining words. Our pluralisation rules apply to this macro option.
|
| words |
string |
Message displayed when the number of words reaches the configured maximum, maxlength with countType: "words". This message is displayed visually and through assistive technologies.
|
| words |
object |
Message displayed when the number of words is over the configured maximum, maxlength with countType: "words". This message is displayed visually and through assistive technologies. The component will replace the %{count} placeholder with the number of words above the maximum. Our pluralisation rules apply to this macro option.
|
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the form group (for example to show error state for the whole group). |
| attributes | object | HTML attributes (for example data attributes) to add to the form group. |
| before |
object |
Content to add before the textarea used by the character count component.
See macro options for form |
| after |
object |
Content to add after the textarea used by the character count component.
See macro options for form |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add before the textarea. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add before the textarea. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
Text to add after the textarea. If html is provided, the text option will be ignored.
|
| html | string |
Required.
HTML to add after the textarea. If html is provided, the text option will be ignored.
|
| Name | Type | Description |
|---|---|---|
| classes | string | Classes to add to the count message. |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text to use within the label. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML to use within the label. If html is provided, the text option will be ignored.
|
| for | string |
The value of the for attribute, the ID of the input the label is associated with.
|
| is |
boolean | Whether the label also acts as the heading for the page. |
| classes | string | Classes to add to the label tag. |
| attributes | object | HTML attributes (for example data attributes) to add to the label tag. |
| Name | Type | Description |
|---|---|---|
| text | string |
Required.
If html is set, this is not required. Text to use within the hint. If html is provided, the text option will be ignored.
|
| html | string |
Required.
If text is set, this is not required. HTML to use within the hint. If html is provided, the text option will be ignored.
|
| id | string | Optional ID attribute to add to the hint span tag. |
| classes | string | Classes to add to the hint span tag. |
| attributes | object | HTML attributes (for example data attributes) to add to the hint span tag. |