feat: streamlined rendering of fields as static text in forms

This commit is contained in:
Björn Fromme
2026-03-16 12:00:55 +01:00
parent da5b913757
commit ef15772b97
+101 -60
View File
@@ -4,10 +4,16 @@
{# Field is in form structure - render normally as form input #}
{{ form_row(form[fieldName], options) }}
{% elseif is_static_text(fieldName, bookingDto, participantIndex) %}
{# Field excluded from form but should render as static text #}
<div class="mb-1">
<label class="font-semibold block">{{ label }}</label>
<div class="text-sm text-gray-600">{{ staticValue ?: '-' }}</div>
{# Field excluded from form - render as static text in fieldset/table style #}
<div class="pb-4">
<fieldset class="border border-primary-bg">
<legend class="w-full bg-primary-bg p-2 font-semibold uppercase">{{ label }}</legend>
<table class="w-full table-fixed border-collapse">
<tr>
<td class="border border-primary-bg p-2">{{ staticValue ?: '-' }}</td>
</tr>
</table>
</fieldset>
</div>
{% endif %}
{# If neither condition is true, don't render anything (truly hidden) #}
@@ -169,65 +175,100 @@
} %}
{% endif %}
{# Personal data section #}
<div class="grid lg:grid-cols-2 lg:gap-x-8">
{{ macros.field_or_static(form, 'firstName', 'Vorname', form.vars.data.participant.firstName, bookingDto, participantIndex) }}
{{ macros.field_or_static(form, 'lastName', 'Nachname', form.vars.data.participant.lastName, bookingDto, participantIndex) }}
{{ macros.field_or_static(
form,
'dateOfBirth',
'Geburtsdatum',
form.vars.data.participant.dateOfBirth ? form.vars.data.participant.dateOfBirth|date('d.m.Y') : null,
bookingDto,
participantIndex,
{
'attr': {
'hx-trigger': 'change',
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
'hx-target': '#main-content',
'hx-swap': 'innerHTML'
}
}
) }}
{# Personal data and address section #}
{% set isPersonalDataStatic = is_static_text('firstName', bookingDto, participantIndex) %}
{% set isAddressStatic = is_static_text('address', bookingDto, participantIndex) %}
{% set genderLabel = form.vars.data.participant.gender == 'M' ? 'männlich' : (form.vars.data.participant.gender == 'W' ? 'weiblich' : (form.vars.data.participant.gender == 'D' ? 'divers' : null)) %}
{{ macros.field_or_static(form, 'gender', 'Geschlecht', genderLabel, bookingDto, participantIndex) }}
{{ macros.field_or_static(form, 'nationality', 'Nationalität', form.vars.data.participant.nationality|map_nationality, bookingDto, participantIndex) }}
{# Contact information #}
{{ macros.field_or_static(form, 'email', 'E-Mail', form.vars.data.participant.email, bookingDto, participantIndex) }}
{{ macros.field_or_static(form, 'mobile', 'Telefon (mobil)', form.vars.data.participant.mobile, bookingDto, participantIndex) }}
</div>
{# Address #}
{% if form.address is defined %}
<div class="grid lg:grid-cols-2 lg:gap-x-8">
{# Address field is in form - render as editable form fields #}
{{ form_row(form.address.street) }}
{{ form_row(form.address.postCode) }}
{{ form_row(form.address.city) }}
{{ form_row(form.address.country) }}
</div>
{% elseif is_static_text('address', bookingDto, participantIndex) %}
{# Address excluded from form but should render as static text #}
{# For applicant (index 0), use booking.applicant.address which has full data from BPN #}
{# For other participants, use participants[index].address (may only have country in BPN response) #}
{% if isPersonalDataStatic and isAddressStatic %}
{# Both personal data and address are static - render in two-column grid with tables #}
{% set participant = form.vars.data.participant %}
{% set addressSource = (0 == participantIndex and bookingDto.booking) ? bookingDto.booking.applicant : bookingDto.participants[participantIndex] %}
<div>
<label class="font-semibold mb-1 block">Adresse</label>
{% if addressSource.address %}
<div class="text-sm text-gray-600">
{% if addressSource.address.street %}{{ addressSource.address.street }}<br>{% endif %}
{% if addressSource.address.postCode or addressSource.address.city %}
{{ addressSource.address.postCode }} {{ addressSource.address.city }}<br>
{% endif %}
{% if addressSource.address.country %}{{ addressSource.address.country|map_country }}{% endif %}
</div>
{% else %}
<div class="text-sm text-gray-600">-</div>
{% endif %}
{% set genderLabel = participant.gender == 'M' ? 'männlich' : (participant.gender == 'W' ? 'weiblich' : (participant.gender == 'D' ? 'divers' : null)) %}
<div class="grid lg:grid-cols-2 lg:gap-x-8 pb-4">
{# Personal data #}
<div class="pb-4 lg:pb-0">
<fieldset class="border border-primary-bg">
<legend class="w-full bg-primary-bg p-2 font-semibold uppercase">Persönliche Daten</legend>
<table class="w-full table-fixed border-collapse">
<tr>
<td class="border border-primary-bg p-2">
<strong>Name:</strong> {{ participant.firstName }} {{ participant.lastName }}<br>
<strong>Geburtsdatum:</strong> {{ participant.dateOfBirth ? participant.dateOfBirth|date('d.m.Y') : '-' }}<br>
<strong>Geschlecht:</strong> {{ genderLabel ?: '-' }}<br>
<strong>Nationalität:</strong> {{ participant.nationality ? participant.nationality|map_nationality : '-' }}<br>
<strong>E-Mail:</strong> {{ participant.email ?: '-' }}<br>
<strong>Telefon:</strong> {{ participant.mobile ?: '-' }}
</td>
</tr>
</table>
</fieldset>
</div>
{# Address #}
<div>
<fieldset class="border border-primary-bg">
<legend class="w-full bg-primary-bg p-2 font-semibold uppercase">Adresse</legend>
<table class="w-full table-fixed border-collapse">
<tr>
<td class="border border-primary-bg p-2">
{% if addressSource.address %}
{% if addressSource.address.street %}{{ addressSource.address.street }}<br>{% endif %}
{% if addressSource.address.postCode or addressSource.address.city %}
{{ addressSource.address.postCode }} {{ addressSource.address.city }}<br>
{% endif %}
{% if addressSource.address.country %}{{ addressSource.address.country|map_country }}{% endif %}
{% else %}
-
{% endif %}
</td>
</tr>
</table>
</fieldset>
</div>
</div>
{% else %}
{# Editable form fields for personal data #}
<div class="grid lg:grid-cols-2 lg:gap-x-8">
{{ macros.field_or_static(form, 'firstName', 'Vorname', form.vars.data.participant.firstName, bookingDto, participantIndex) }}
{{ macros.field_or_static(form, 'lastName', 'Nachname', form.vars.data.participant.lastName, bookingDto, participantIndex) }}
{{ macros.field_or_static(
form,
'dateOfBirth',
'Geburtsdatum',
form.vars.data.participant.dateOfBirth ? form.vars.data.participant.dateOfBirth|date('d.m.Y') : null,
bookingDto,
participantIndex,
{
'attr': {
'hx-trigger': 'change',
'hx-post': path(refreshRouteName, refreshRouteParams|default({index: participantIndex})),
'hx-target': '#main-content',
'hx-swap': 'innerHTML'
}
}
) }}
{% set genderLabel = form.vars.data.participant.gender == 'M' ? 'männlich' : (form.vars.data.participant.gender == 'W' ? 'weiblich' : (form.vars.data.participant.gender == 'D' ? 'divers' : null)) %}
{{ macros.field_or_static(form, 'gender', 'Geschlecht', genderLabel, bookingDto, participantIndex) }}
{{ macros.field_or_static(form, 'nationality', 'Nationalität', form.vars.data.participant.nationality|map_nationality, bookingDto, participantIndex) }}
{# Contact information #}
{{ macros.field_or_static(form, 'email', 'E-Mail', form.vars.data.participant.email, bookingDto, participantIndex) }}
{{ macros.field_or_static(form, 'mobile', 'Telefon (mobil)', form.vars.data.participant.mobile, bookingDto, participantIndex) }}
</div>
{# Address #}
{% if form.address is defined %}
<div class="grid lg:grid-cols-2 lg:gap-x-8">
{# Address field is in form - render as editable form fields #}
{{ form_row(form.address.street) }}
{{ form_row(form.address.postCode) }}
{{ form_row(form.address.city) }}
{{ form_row(form.address.country) }}
</div>
{% endif %}
{% endif %}
{# Room assignment - hidden until date of birth is provided, or shown as static text in edit mode #}