feat: improved handling of fields to be rendered as static text
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
{% import _self as macros %}
|
||||
|
||||
{# Macro to render a form field or static value #}
|
||||
{% macro field_or_static(form, fieldName, label, staticValue, options = {}) %}
|
||||
{# Macro to render a form field or static value based on field state #}
|
||||
{% macro field_or_static(form, fieldName, label, staticValue, bookingDto, participantIndex, options = {}) %}
|
||||
{% if form[fieldName] is defined %}
|
||||
{# Field is in form structure - render normally as form input #}
|
||||
{{ form_row(form[fieldName], options) }}
|
||||
{% else %}
|
||||
<div>
|
||||
<label class="font-semibold mb-1 block">{{ label }}</label>
|
||||
{% 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>
|
||||
</div>
|
||||
{% endif %}
|
||||
{# If neither condition is true, don't render anything (truly hidden) #}
|
||||
{% endmacro %}
|
||||
|
||||
{# Macro to render a field or placeholder with consistent fieldset structure #}
|
||||
@@ -69,14 +72,16 @@
|
||||
<div id="participant-form" class="space-y-4">
|
||||
{# Personal data section #}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ macros.field_or_static(form, 'firstName', 'Vorname', form.vars.data.participant.firstName) }}
|
||||
{{ macros.field_or_static(form, 'lastName', 'Nachname', form.vars.data.participant.lastName) }}
|
||||
{{ 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',
|
||||
@@ -88,35 +93,40 @@
|
||||
) }}
|
||||
|
||||
{% 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) }}
|
||||
{{ macros.field_or_static(form, 'gender', 'Geschlecht', genderLabel, bookingDto, participantIndex) }}
|
||||
|
||||
{{ macros.field_or_static(form, 'nationality', 'Nationalität', form.vars.data.participant.nationality) }}
|
||||
{{ macros.field_or_static(form, 'nationality', 'Nationalität', form.vars.data.participant.nationality|map_nationality, bookingDto, participantIndex) }}
|
||||
</div>
|
||||
|
||||
{# Contact information #}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ macros.field_or_static(form, 'email', 'E-Mail', form.vars.data.participant.email) }}
|
||||
{{ macros.field_or_static(form, 'mobile', 'Telefon (mobil)', form.vars.data.participant.mobile) }}
|
||||
{{ 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 %}
|
||||
{# Address field is in form - render as editable form fields #}
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
{{ form_row(form.address.street) }}
|
||||
{{ form_row(form.address.postCode) }}
|
||||
{{ form_row(form.address.city) }}
|
||||
{{ form_row(form.address.country) }}
|
||||
</div>
|
||||
{% else %}
|
||||
{% 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) #}
|
||||
{% set addressSource = (0 == participantIndex and bookingDto.booking) ? bookingDto.booking.applicant : bookingDto.participants[participantIndex] %}
|
||||
<div>
|
||||
<label class="font-semibold mb-1 block">Adresse</label>
|
||||
{% if form.vars.data.participant.address %}
|
||||
{% if addressSource.address %}
|
||||
<div class="text-sm text-gray-600">
|
||||
{% if form.vars.data.participant.address.street %}{{ form.vars.data.participant.address.street }}<br>{% endif %}
|
||||
{% if form.vars.data.participant.address.postCode or form.vars.data.participant.address.city %}
|
||||
{{ form.vars.data.participant.address.postCode }} {{ form.vars.data.participant.address.city }}<br>
|
||||
{% 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 form.vars.data.participant.address.country %}{{ form.vars.data.participant.address.country }}{% endif %}
|
||||
{% if addressSource.address.country %}{{ addressSource.address.country|map_country }}{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="text-sm text-gray-600">-</div>
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
{% use 'form_div_layout.html.twig' %}
|
||||
|
||||
{# Macro to render a static (read-only) field value with consistent formatting #}
|
||||
{% macro render_static_field(label, value) %}
|
||||
<div class="mb-1">
|
||||
<label class="font-semibold block">{{ label }}</label>
|
||||
<div class="text-sm text-gray-600">{{ value ?: '-' }}</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{# Macro to render info icon tooltip for descriptions #}
|
||||
{% macro info_tooltip(description) %}
|
||||
<div class="pt-px pl-1" {{ stimulus_controller('tooltip') }}>
|
||||
|
||||
Reference in New Issue
Block a user