{% load helpers %} {% load form_helpers %} {% comment %} Django already emits `aria-describedby="_helptext _error"` on the widget (plus `aria-invalid` and `required` where applicable) -- see `BoundField.aria_describedby`. Those ids have to actually exist on the elements holding the help text and the error list, otherwise the reference dangles and assistive technology announces nothing. Hence the `id` attributes below; do not rename them without matching Django's naming (WCAG 1.3.1, 3.3.1, 3.3.2). {% endcomment %} {# If the form field carries an `htmx_attrs` dict, wrap output in a persistent HTMX swap target. #} {# The wrapper's innerHTML is replaced on each swap; the wrapper itself persists across swaps so #} {# its HTMX attributes do not need to be re-emitted by the partial that returns the new content. #} {% if field.field.htmx_attrs %}
{% endif %} {% if field|widget_type == 'checkboxinput' %}
{{ field }}
{% if bulk_nullable %}
{% endif %} {% if field.help_text %} {{ field.help_text|safe }} {% endif %} {% elif field|widget_type == 'textarea' and not field.label %}
{% comment %} This branch exists for full-width textareas that deliberately show no visible label (Comments being the common case). "No visible label" is not the same as "no label", so emit a visually hidden one; otherwise the field is announced as an unlabelled text area. Falls back to the field name when there is no label at all. {% endcomment %} {{ field }} {% if bulk_nullable %}
{% endif %} {% if field.help_text %} {{ field.help_text|safe }} {% endif %} {% else %}
{% if field.field.htmx_attrs %}
{% endif %}