From 2e602b85b26b8ca006d1d0dd4162505faffcb1dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 21 May 2025 15:20:09 +0200 Subject: [PATCH] feat: improved validation error rendering of booking form --- assets/styles/components/forms.css | 4 ++-- templates/_partials/_alert.html.twig | 20 +++++++++----------- templates/booking/edit.html.twig | 23 +++++++++++++++++------ templates/forms.html.twig | 6 +++--- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/assets/styles/components/forms.css b/assets/styles/components/forms.css index b722f56..19d52c5 100644 --- a/assets/styles/components/forms.css +++ b/assets/styles/components/forms.css @@ -8,7 +8,7 @@ label.required:after { } .form-field--has-error { - @apply border-red-500; + @apply border-red-700; } .form-checkbox, @@ -18,7 +18,7 @@ label.required:after { .form-checkbox--has-error, .form-radio--has-error { - @apply border-red-500; + @apply border-red-700; } select[readonly] { diff --git a/templates/_partials/_alert.html.twig b/templates/_partials/_alert.html.twig index cd982be..36b0941 100644 --- a/templates/_partials/_alert.html.twig +++ b/templates/_partials/_alert.html.twig @@ -19,19 +19,17 @@ {% endif %}
- {% if messages | length == 1 %} -

- {{ messages[0] }} -

- {% else %} -

- {{ title is defined ? title : 'Es gab mehrere Probleme' }} -

-
-
    + {% if title is defined %} +
    + {{ title }} +
    + {% endif %} + {% if messages is defined %} +
    +
      {% for message in messages %}
    • - {{ message }} + {{ message|raw }}
    • {% endfor %}
    diff --git a/templates/booking/edit.html.twig b/templates/booking/edit.html.twig index 9753cc9..c96acbe 100644 --- a/templates/booking/edit.html.twig +++ b/templates/booking/edit.html.twig @@ -4,8 +4,19 @@ {% include '_partials/_flashes.html.twig' %} {{ form_start(form) }} {% if not form.vars.valid %} - {% set messages = form.vars.errors|map(error => error.message) %} - {% include '_partials/_alert.html.twig' with { 'level': 'error', 'title': 'Die Buchung konnte nicht aktualisiert werden', 'messages': messages } %} + {% include '_partials/_alert.html.twig' with { 'level': 'error', 'title': 'Die Buchung konnte nicht aktualisiert werden' } %} + {% for child in form.participants.children %} + {% if not child.vars.valid %} + {% set participant = child.vars.data %} + {% set messages = [] %} + {% for field in child.children %} + {% for error in field.vars.errors %} + {% set messages = messages|merge([field.vars.label ~ ': ' ~ error.message]) %} + {% endfor %} + {% endfor %} + {% include '_partials/_alert.html.twig' with { 'level': 'error', 'title': 'Teilnehmer:in ' ~ participant.index ~ ':' ~ participant.firstName ~ participant.lastName, 'messages': messages } %} + {% endif %} + {% endfor %} {% endif %}
    {% for child in form.participants %} -
    - {% set participant = child.vars.data %} + {% set participant = child.vars.data %} +
    {% if participant.status == 'S' %} {% do child.setRendered %} {% endif %} -
    +
    Teilnehmer:in {{ participant.index }}: {{ participant.firstName }} {{ participant.lastName }} - {% if participant.status == 'S' %} storniert{% endif %} + {% if participant.status == 'S' %} storniert{% endif %}
    diff --git a/templates/forms.html.twig b/templates/forms.html.twig index 6dc76b0..71728b0 100644 --- a/templates/forms.html.twig +++ b/templates/forms.html.twig @@ -17,7 +17,7 @@ {%- block form_label -%} {% set class = 'font-semibold' %} {% if errors|length %} - {% set class = class ~ ' text-red-500' %} + {% set class = class ~ ' text-red-700' %} {% endif %} {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ class)|trim}) %} {{ parent() }} @@ -27,7 +27,7 @@ {%- if errors|length > 0 -%}
      {%- for error in errors -%} -
    • {{ error.message }}
    • +
    • {{ error.message }}
    • {%- endfor -%}
    {%- endif -%} @@ -99,7 +99,7 @@
    {{ form_widget(form) }}
    -
    +