{# @description A single presentational form field: control plus optional label, help text, and errors. #} {# @prop type:text | default:"text" | description:"Any text-like input type, or textarea, select, file, checkbox, radio, toggle." #} {# @prop label:text | description:"Field label; also accepts a named slot of the same name for rich content." #} {# @prop hide-label:boolean | description:"Visually hide the label while keeping it accessible." #} {# @prop help-text:text | description:"Help text shown below the control; also accepts a named slot." #} {# @prop errors:text | description:"A string or list of errors; switches the control to its error style. Also accepts a named slot." #} {# @prop prelabel:text | description:"Inline label before the control (select/text inputs)." #} {# @prop postlabel:text | description:"Inline label after the control (select/text inputs)." #} {# @prop class:text | description:"Extra classes on the control element." #} {# @prop wrapper-class:text | description:"Extra classes on the fieldset wrapper." #} {# @slot Extra control content — Fills the textarea value, select options, or extra inline content. #} {# @slot:label Rich label markup — Alternative to label for rich content, e.g. a badge. #} {# @slot:help_text Rich help text markup — Alternative to help-text. #} {# @slot:errors Rich error markup — Alternative to errors. #} {% comment %} The fieldset wrapper only renders when there is something to put in it, so a bare field stays a single control that composes inside joins and toolbars. Check-style controls carry their label inline, so they never need a legend. {% endcomment %} {% if type == "checkbox" or type == "radio" or type == "toggle" %} {% firstof help_text errors as wrapped %} {% firstof "" as legend %} {% else %} {% firstof label help_text errors as wrapped %} {% firstof label as legend %} {% endif %} {# djlint:off #} {% if wrapped %}
{% if legend %} {% endif %} {% endif %} {% if type == "textarea" %} {% elif type == "select" %} {% elif type == "file" %} {% elif type == "checkbox" or type == "radio" or type == "toggle" %} {% else %} {% endif %} {% if wrapped %} {% if help_text %}

{{ help_text }}

{% endif %} {% if errors %}

{% if errors == errors|stringformat:"s" %} {{ errors }} {% else %} {% for error in errors %}{{ error }}{% if not forloop.last %}
{% endif %}{% endfor %} {% endif %}

{% endif %}
{% endif %} {# djlint:on #}