{% macro govukInput(params) %} {% from "govuk_frontend_jinja/macros/attributes.html" import govukAttributes %} {% from "govuk_frontend_jinja/components/error-message/macro.html" import govukErrorMessage %} {% from "govuk_frontend_jinja/components/hint/macro.html" import govukHint %} {% from "govuk_frontend_jinja/components/label/macro.html" import govukLabel %} {#- a record of other elements that we need to associate with the input using aria-describedby – for example hints or error messages -#} {% set describedBy = params.describedBy if params.describedBy else "" -%} {%- set hasPrefix = true if params.prefix and (params.prefix.text or params.prefix.html) else false %} {%- set hasSuffix = true if params.suffix and (params.suffix.text or params.suffix.html) else false %} {%- set hasBeforeInput = true if params.formGroup and params.formGroup.beforeInput and (params.formGroup.beforeInput.text or params.formGroup.beforeInput.html) else false %} {%- set hasAfterInput = true if params.formGroup and params.formGroup.afterInput and (params.formGroup.afterInput.text or params.formGroup.afterInput.html) else false %} {%- macro _inputElement(params) -%} {%- endmacro -%} {%- macro _affixItem(affix, type) %} {%- endmacro -%}
{{ govukLabel({ 'html': params.label.html, 'text': params.label.text, 'classes': params.label.classes, 'isPageHeading': params.label.isPageHeading, 'attributes': params.label.attributes, 'for': params.id }) | trim | indent(2) }} {% if params.hint %} {% set hintId = params.id + '-hint' %} {% set describedBy = describedBy + ' ' + hintId if describedBy else hintId %} {{ govukHint({ 'id': hintId, 'classes': params.hint.classes, 'attributes': params.hint.attributes, 'html': params.hint.html, 'text': params.hint.text }) | trim | indent(2) }} {% endif %} {% if params.errorMessage %} {% set errorId = params.id + '-error' %} {% set describedBy = describedBy + ' ' + errorId if describedBy else errorId %} {{ govukErrorMessage({ 'id': errorId, 'classes': params.errorMessage.classes, 'attributes': params.errorMessage.attributes, 'html': params.errorMessage.html, 'text': params.errorMessage.text, 'visuallyHiddenText': params.errorMessage.visuallyHiddenText }) | trim | indent(2) }} {% endif %} {%- if hasPrefix or hasSuffix or hasBeforeInput or hasAfterInput %}
{% if hasBeforeInput %} {{- params.formGroup.beforeInput.html | safe | trim | indent(4, true) if params.formGroup.beforeInput.html else params.formGroup.beforeInput.text }} {% endif %} {% if hasPrefix %} {{- _affixItem(params.prefix, "prefix") | indent(2, true) }} {% endif %} {{ _inputElement(params) }} {% if hasSuffix %} {{- _affixItem(params.suffix, "suffix") | indent(2, true) }} {% endif %} {% if hasAfterInput %} {{- params.formGroup.afterInput.html | safe | trim | indent(4, true) if params.formGroup.afterInput.html else params.formGroup.afterInput.text }} {% endif %}
{% else %} {{ _inputElement(params) }} {% endif %}
{% endmacro %}