Text input 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 Text input 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.

Primary options
Name Type Description
id string The ID of the input. Defaults to the value of name.
name string Required. The name of the input, which is submitted with the form data.
type string Type of input control to render, for example, a password input control. Defaults to "text".
inputmode string Optional value for the inputmode attribute.
value string Optional initial value of the input.
disabled boolean If true, input will be disabled.
describedBy string One or more element IDs to add to the aria-describedby attribute, used to provide additional descriptive information for screenreader users.
label object Required. The label used by the text input component. See macro options for label.
hint object Can be used to add a hint to a text input component. See macro options for hint.
errorMessage object Can be used to add an error message to the text input 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 errorMessage.
prefix object Can be used to add a prefix to the text input component. See macro options for prefix.
suffix object Can be used to add a suffix to the text input component. See macro options for suffix.
formGroup object Additional options for the form group containing the text input component. See macro options for formGroup.
classes string Classes to add to the input.
autocomplete string Attribute to meet WCAG success criterion 1.3.5: Identify input purpose, for instance "bday-day". See the Autofill section in the HTML standard section in the HTML standard for full list of attributes that can be used.
pattern string Attribute to provide a regular expression pattern, used to match allowed character combinations for the input value.
spellcheck boolean Optional field to enable or disable the spellcheck attribute on the input.
autocapitalize string Optional field to enable or disable autocapitalisation of user input. See the Autocapitalization section in the HTML spec for a full list of values that can be used.
inputWrapper object If any of prefix, suffix, formGroup.beforeInput or formGroup.afterInput have a value, a wrapping element is added around the input and inserted content. This object allows you to customise that wrapping element. See macro options for inputWrapper.
attributes object HTML attributes (for example data attributes) to add to the input.
Options for prefix object
Name Type Description
text string Required. Required. If html is set, this is not required. Text to use within the prefix. If html is provided, the text option will be ignored.
html string Required. Required. If text is set, this is not required. HTML to use within the prefix. If html is provided, the text option will be ignored.
classes string Classes to add to the prefix.
attributes object HTML attributes (for example data attributes) to add to the prefix element.
Options for suffix object
Name Type Description
text string Required. If html is set, this is not required. Text to use within the suffix. 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 suffix. If html is provided, the text option will be ignored.
classes string Classes to add to the suffix element.
attributes object HTML attributes (for example data attributes) to add to the suffix element.
Options for formGroup object
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.
beforeInput object Content to add before the input used by the text input component. See macro options for formGroup beforeInput.
afterInput object Content to add after the input used by the text input component. See macro options for formGroup afterInput.
Options for formGroup beforeInput object
Name Type Description
text string Required. Text to add before the input. If html is provided, the text option will be ignored.
html string Required. HTML to add before the input. If html is provided, the text option will be ignored.
Options for formGroup afterInput object
Name Type Description
text string Required. Text to add after the input. If html is provided, the text option will be ignored.
html string Required. HTML to add after the input. If html is provided, the text option will be ignored.
Options for inputWrapper object
Name Type Description
classes string Classes to add to the wrapping element.
attributes object HTML attributes (for example data attributes) to add to the wrapping element.
Options for label component
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.
isPageHeading 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.
Options for hint component
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.