Files
myep/templates/forms_admin.html.twig
T

94 lines
3.3 KiB
Twig

{#
Form theme in the look of the apps template's Field.tsx: a real label, the hint and the error
below the input, which gets aria-invalid and aria-describedby.
#}
{% extends 'form_div_layout.html.twig' %}
{% block form_row %}
{% set describedBy = [help ? id ~ '_help', errors|length ? id ~ '_errors']|filter(v => v) %}
{% set widget_attr = {attr: {'aria-describedby': describedBy ? describedBy|join(' ')}|filter(v => v)
|merge(errors|length ? {'aria-invalid': 'true'} : {})} %}
<div class="{{ row_attr.class ?? '' }}">
{{ form_label(form) }}
{{ form_widget(form, widget_attr) }}
{{ form_help(form) }}
{{ form_errors(form) }}
</div>
{% endblock %}
{# the box in front of its label, the hint below #}
{% block checkbox_row %}
{% set describedBy = [help ? id ~ '_help', errors|length ? id ~ '_errors']|filter(v => v) %}
<div class="{{ row_attr.class ?? '' }}">
<label class="flex items-center gap-2 pt-6" for="{{ id }}">
{{ form_widget(form, {attr: {class: 'rounded'}|merge(describedBy ? {'aria-describedby': describedBy|join(' ')} : {})}) }}
{{ label }}
</label>
{{ form_help(form) }}
{{ form_errors(form) }}
</div>
{% endblock %}
{% block form_label %}
{% if label is not same as(false) %}
{% set label_attr = label_attr|merge({class: 'field-label mb-1 ' ~ (label_attr.class ?? '')}) %}
{{ parent() }}
{% endif %}
{% endblock %}
{% block form_label_content %}
{{- parent() -}}
{%- if required %}<span aria-hidden="true" class="text-red-800"> *</span><span class="sr-only"> (Pflichtfeld)</span>{% endif -%}
{% endblock %}
{% block form_widget_simple %}
{% set attr = attr|merge({class: 'input ' ~ (attr.class ?? '')}) %}
{{ parent() }}
{% endblock %}
{% block choice_widget_collapsed %}
{% set attr = attr|merge({class: 'input ' ~ (attr.class ?? '')}) %}
{{ parent() }}
{% endblock %}
{% block form_help %}
{% if help %}
<p id="{{ id }}_help" class="mt-1 text-xs text-slate-600">{{ help }}</p>
{% endif %}
{% endblock %}
{% block form_errors %}
{% if errors|length %}
<p id="{{ id }}_errors" class="mt-1 text-xs font-bold text-red-800">
{%- for error in errors %}{{ error.message }}{% if not loop.last %} {% endif %}{% endfor -%}
</p>
{% endif %}
{% endblock %}
{# myep additions for the admin forms #}
{% block textarea_widget %}
{% set attr = attr|merge({class: 'input ' ~ (attr.class ?? '')}) %}
{{ parent() }}
{% endblock %}
{# a list of boxes or radios, each in front of its label #}
{% block choice_widget_expanded %}
<div {{ block('widget_container_attributes') }}>
{% for child in form %}
<label class="flex items-center gap-2 py-1 text-sm" for="{{ child.vars.id }}">
{{ form_widget(child) }}
{{ child.vars.label|trans(child.vars.label_translation_parameters, child.vars.translation_domain) }}
</label>
{% endfor %}
</div>
{% endblock %}
{# the currency inside the field, on the right #}
{% block money_widget %}
<div class="relative">
{{ block('form_widget_simple') }}
<span class="pointer-events-none absolute top-1/2 right-0 mr-3 -translate-y-1/2 text-sm text-muted">{{ money_pattern|replace({'{{ widget }}': ''})|trim }}</span>
</div>
{% endblock %}