Checkboxes 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 Checkboxes 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
describedBy string One or more element IDs to add to the input aria-describedby attribute without a fieldset, used to provide additional descriptive information for screenreader users.
fieldset object Can be used to add a fieldset to the checkboxes component. See macro options for fieldset.
hint object Can be used to add a hint to the checkboxes component. See macro options for hint.
errorMessage object Can be used to add an error message to the checkboxes 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.
formGroup object Additional options for the form group containing the checkboxes component. See macro options for formGroup.
idPrefix string Optional prefix. This is used to prefix the id attribute for each checkbox item input, hint and error message, separated by -. Defaults to the name option value.
name string Required. Name attribute for all checkbox items.
items array Required. The checkbox items within the checkboxes component. See macro options for items.
values array Array of values for checkboxes which should be checked when the page loads. Use this as an alternative to setting the checked option on each individual item.
classes string Classes to add to the checkboxes container.
attributes object HTML attributes (for example data attributes) to add to the checkboxes container.
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.
beforeInputs object Content to add before all checkbox items within the checkboxes component. See macro options for formGroup beforeInputs.
afterInputs object Content to add after all checkbox items within the checkboxes component. See macro options for formGroup afterInputs.
Options for formGroup beforeInputs object
Name Type Description
text string Required. Text to add before all checkbox items. If html is provided, the text option will be ignored.
html string Required. HTML to add before all checkbox items. If html is provided, the text option will be ignored.
Options for formGroup afterInputs object
Name Type Description
text string Required. Text to add after all checkbox items. If html is provided, the text option will be ignored.
html string Required. HTML to add after all checkbox items. If html is provided, the text option will be ignored.
Options for items array objects
Name Type Description
text string Required. If html is set, this is not required. Text to use within each checkbox item 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 each checkbox item label. If html is provided, the text option will be ignored.
id string Specific ID attribute for the checkbox item. If omitted, then component global idPrefix option will be applied.
name string Specific name for the checkbox item. If omitted, then component global name string will be applied.
value string Required. Value for the checkbox input.
label object Subset of options for the label used by each checkbox item within the checkboxes component. See macro options for items label.
hint object Can be used to add a hint to each checkbox item within the checkboxes component. See macro options for hint.
divider string Divider text to separate checkbox items, for example the text "or".
checked boolean Whether the checkbox should be checked when the page loads. Takes precedence over the top-level values option.
conditional object Provide additional content to reveal when the checkbox is checked. See macro options for items conditional.
behaviour string If set to "exclusive", implements a ‘None of these’ type behaviour via JavaScript when checkboxes are clicked.
disabled boolean If true, checkbox will be disabled.
attributes object HTML attributes (for example data attributes) to add to the checkbox input tag.
Options for items label component
Name Type Description
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 items conditional object
Name Type Description
html string Required. The HTML to reveal when the checkbox is checked.
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.