Character count examples
-
# default
{ "name": "more-detail", "maxlength": 10, "label": { "text": "Can you provide more detail?" } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "name": "more-detail", "maxlength": 10, "label": { "text": "Can you provide more detail?" } }) }} -
# with hint
Don't include personal or financial information, eg your National Insurance number or credit card details.{ "name": "with-hint", "id": "with-hint", "maxlength": 10, "label": { "text": "Can you provide more detail?" }, "hint": { "text": "Don't include personal or financial information, eg your National Insurance number or credit card details." } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "name": "with-hint", "id": "with-hint", "maxlength": 10, "label": { "text": "Can you provide more detail?" }, "hint": { "text": "Don't include personal or financial information, eg your National Insurance number or credit card details." } }) }} -
# with hint and error
Don't include personal or financial information, eg your National Insurance number or credit card details.{ "name": "with-error", "id": "with-error", "maxlength": 10, "label": { "text": "Can you provide more detail?" }, "errorMessage": { "text": "Please provide more detail" }, "hint": { "text": "Don't include personal or financial information, eg your National Insurance number or credit card details." } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "name": "with-error", "id": "with-error", "maxlength": 10, "label": { "text": "Can you provide more detail?" }, "errorMessage": { "text": "Please provide more detail" }, "hint": { "text": "Don't include personal or financial information, eg your National Insurance number or credit card details." } }) }} -
# with default value
{ "id": "with-default-value", "name": "default-value", "maxlength": 100, "label": { "text": "Full address" }, "value": "221B Baker Street\nLondon\nNW1 6XE\n" }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "with-default-value", "name": "default-value", "maxlength": 100, "label": { "text": "Full address" }, "value": "221B Baker Street\nLondon\nNW1 6XE\n" }) }} -
# with default value exceeding limit
{ "id": "exceeding-characters", "name": "exceeding", "maxlength": 10, "value": "221B Baker Street\nLondon\nNW1 6XE\n", "label": { "text": "Full address" }, "errorMessage": { "text": "Please do not exceed the maximum allowed limit" } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "exceeding-characters", "name": "exceeding", "maxlength": 10, "value": "221B Baker Street\nLondon\nNW1 6XE\n", "label": { "text": "Full address" }, "errorMessage": { "text": "Please do not exceed the maximum allowed limit" } }) }} -
# with custom rows
{ "id": "custom-rows", "name": "custom", "maxlength": 10, "label": { "text": "Full address" }, "rows": 8 }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "custom-rows", "name": "custom", "maxlength": 10, "label": { "text": "Full address" }, "rows": 8 }) }} -
# with label as page heading
{ "id": "textarea-with-page-heading", "name": "address", "maxlength": 10, "label": { "text": "Full address", "classes": "govuk-label--l", "isPageHeading": true } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "textarea-with-page-heading", "name": "address", "maxlength": 10, "label": { "text": "Full address", "classes": "govuk-label--l", "isPageHeading": true } }) }} -
# with word count
{ "id": "word-count", "name": "word-count", "maxwords": 10, "label": { "text": "Full address" } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "word-count", "name": "word-count", "maxwords": 10, "label": { "text": "Full address" } }) }} -
# with threshold
{ "id": "with-threshold", "name": "with-threshold", "maxlength": 10, "threshold": 75, "label": { "text": "Full address" } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "with-threshold", "name": "with-threshold", "maxlength": 10, "threshold": 75, "label": { "text": "Full address" } }) }} -
# with custom textarea description
{ "name": "custom-textarea-description", "id": "custom-textarea-description", "maxlength": 10, "label": { "text": "Can you provide more detail?" }, "textareaDescriptionText": "Gallwch ddefnyddio hyd at %{count} nod" }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "name": "custom-textarea-description", "id": "custom-textarea-description", "maxlength": 10, "label": { "text": "Can you provide more detail?" }, "textareaDescriptionText": "Gallwch ddefnyddio hyd at %{count} nod" }) }} -
# classes
{ "id": "with-classes", "name": "with-classes", "maxlength": 10, "label": { "text": "With classes" }, "classes": "app-character-count--custom-modifier" }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "with-classes", "name": "with-classes", "maxlength": 10, "label": { "text": "With classes" }, "classes": "app-character-count--custom-modifier" }) }} -
# id
{ "id": "character-count-id", "name": "test-name", "maxlength": 10, "label": { "text": "With custom id" } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "character-count-id", "name": "test-name", "maxlength": 10, "label": { "text": "With custom id" } }) }} -
# attributes
{ "id": "with-attributes", "name": "with-attributes", "maxlength": 10, "label": { "text": "With attributes" }, "attributes": { "data-attribute": "my data value" } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "with-attributes", "name": "with-attributes", "maxlength": 10, "label": { "text": "With attributes" }, "attributes": { "data-attribute": "my data value" } }) }} -
# formGroup with classes
{ "id": "with-formgroup", "name": "with-formgroup", "maxlength": 10, "label": { "text": "With formgroup" }, "formGroup": { "classes": "app-character-count--custom-modifier" } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "with-formgroup", "name": "with-formgroup", "maxlength": 10, "label": { "text": "With formgroup" }, "formGroup": { "classes": "app-character-count--custom-modifier" } }) }} -
# custom classes on countMessage
{ "id": "with-custom-countmessage-class", "name": "with-custom-countmessage-class", "maxlength": 10, "label": { "text": "With custom countMessage class" }, "countMessage": { "classes": "app-custom-count-message" } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "with-custom-countmessage-class", "name": "with-custom-countmessage-class", "maxlength": 10, "label": { "text": "With custom countMessage class" }, "countMessage": { "classes": "app-custom-count-message" } }) }} -
# spellcheck enabled
{ "id": "with-spellcheck", "name": "with-spellcheck", "maxlength": 10, "label": { "text": "With spellcheck" }, "spellcheck": true }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "with-spellcheck", "name": "with-spellcheck", "maxlength": 10, "label": { "text": "With spellcheck" }, "spellcheck": true }) }} -
# spellcheck disabled
{ "id": "without-spellcheck", "name": "without-spellcheck", "maxlength": 10, "label": { "text": "Without spellcheck" }, "spellcheck": false }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "without-spellcheck", "name": "without-spellcheck", "maxlength": 10, "label": { "text": "Without spellcheck" }, "spellcheck": false }) }} -
# custom classes with error message
{ "id": "with-custom-error-class", "name": "with-custom-error-class", "maxlength": 10, "label": { "text": "With custom error class" }, "classes": "app-character-count--custom-modifier", "errorMessage": { "text": "Error message" } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "with-custom-error-class", "name": "with-custom-error-class", "maxlength": 10, "label": { "text": "With custom error class" }, "classes": "app-character-count--custom-modifier", "errorMessage": { "text": "Error message" } }) }} -
# with id starting with number
{ "name": "more-detail", "id": "1_more-detail", "maxlength": 10, "label": { "text": "Can you provide more detail?" } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "name": "more-detail", "id": "1_more-detail", "maxlength": 10, "label": { "text": "Can you provide more detail?" } }) }} -
# with id with special characters
{ "id": "user1.profile[address]", "name": "address", "maxlength": 10, "label": { "text": "Full address" } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "user1.profile[address]", "name": "address", "maxlength": 10, "label": { "text": "Full address" } }) }} -
# with textarea maxlength attribute
{ "id": "maxlength-should-be-removed", "name": "address", "maxlength": 10, "attributes": { "maxlength": 10 }, "label": { "text": "Full address" } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "maxlength-should-be-removed", "name": "address", "maxlength": 10, "attributes": { "maxlength": 10 }, "label": { "text": "Full address" } }) }} -
# to configure in JavaScript
{ "id": "to-configure-in-javascript", "name": "address", "label": { "text": "Full address" } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "to-configure-in-javascript", "name": "address", "label": { "text": "Full address" } }) }} -
# when neither maxlength nor maxwords are set
{ "id": "no-maximum", "name": "no-maximum", "label": { "text": "Full address" }, "textareaDescriptionText": "No more than %{count} characters" }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "no-maximum", "name": "no-maximum", "label": { "text": "Full address" }, "textareaDescriptionText": "No more than %{count} characters" }) }} -
# when neither maxlength/maxwords nor textarea description are set
-
# with translations
{ "id": "with-translations", "name": "with-translations", "maxlength": 10, "label": { "text": "Full address" }, "charactersUnderLimitText": { "other": "%{count} characters to go", "one": "One character to go" }, "charactersAtLimitText": "Zero characters left", "charactersOverLimitText": { "other": "%{count} characters too many", "one": "One character too many" }, "wordsUnderLimitText": { "other": "%{count} words to go", "one": "One word to go" }, "wordsAtLimitText": "Zero words left", "wordsOverLimitText": { "other": "%{count} words too many", "one": "One word too many" } }{% from "govuk/components/character-count/macro.njk" import govukCharacterCount %} {{ govukCharacterCount({ "id": "with-translations", "name": "with-translations", "maxlength": 10, "label": { "text": "Full address" }, "charactersUnderLimitText": { "other": "%{count} characters to go", "one": "One character to go" }, "charactersAtLimitText": "Zero characters left", "charactersOverLimitText": { "other": "%{count} characters too many", "one": "One character too many" }, "wordsUnderLimitText": { "other": "%{count} words to go", "one": "One word to go" }, "wordsAtLimitText": "Zero words left", "wordsOverLimitText": { "other": "%{count} words too many", "one": "One word too many" } }) }}