fix: avoid form jumping to top after making a selection

This commit is contained in:
Björn Fromme
2026-08-04 09:42:01 +02:00
parent dde36ccba2
commit c31d086356
3 changed files with 169 additions and 161 deletions
+1 -1
View File
@@ -72,7 +72,7 @@ class Step2Controller extends AbstractAccommodationController
return $this->htmxOobResponse( return $this->htmxOobResponse(
'groups/booking/step_2.html.twig', 'groups/booking/step_2.html.twig',
['accommodation_form', 'accommodation_summary'], ['booking_form', 'accommodation_summary'],
['dto' => $dto, 'ctx' => $ctx, 'form' => $form->createView()], ['dto' => $dto, 'ctx' => $ctx, 'form' => $form->createView()],
); );
} }
+33 -25
View File
@@ -33,21 +33,48 @@
{# Main form #} {# Main form #}
{% block accommodation_form %} {% block accommodation_form %}
<div id="accommodation-form" <div id="accommodation-form"
class="flex-1 order-2 lg:order-1 lg:col-span-3 bg-white flex flex-col min-h-0" class="flex-1 order-2 lg:order-1 lg:col-span-3 bg-white flex flex-col min-h-0">
{% if htmx_oob_swap is defined and htmx_oob_swap %}hx-swap-oob="true"{% endif %}>
{% include '_partials/_flashes.html.twig' %}
{# Pagination - desktop only (fixed above scrollable content) #} {# Pagination - desktop only (fixed above scrollable content) #}
<div class="hidden lg:block shrink-0"> <div class="hidden lg:block shrink-0">
{% include 'groups/booking/_pagination.html.twig' with { 'current_step': 2 } %} {% include 'groups/booking/_pagination.html.twig' with { 'current_step': 2 } %}
</div> </div>
<div id="participant-form" {# The scroll container itself must survive the htmx refresh — only its contents
are swapped, so assets/loading.js can restore the scroll position. #}
<div id="booking-form"
class="flex-1 overflow-y-auto px-4 lg:px-8 py-8" class="flex-1 overflow-y-auto px-4 lg:px-8 py-8"
hx-post="{{ path('app_groups_booking_step_2_refresh') }}" hx-post="{{ path('app_groups_booking_step_2_refresh') }}"
hx-trigger="change delay:300ms" hx-trigger="change delay:300ms"
hx-swap="none"> hx-target="#booking-form"
hx-swap="innerHTML">
{{ block('booking_form') }}
</div>
</div>
{% endblock %}
</div>
<div class="shrink-0 bg-primary-dark px-4 lg:px-8 py-2 lg:py-4 z-20">
<div class="flex items-center justify-between">
<a href="{{ path('app_groups_booking_step_1') }}" class="button button--secondary">
Zurück
</a>
<button type="submit" class="button button--primary">
Weiter zu Schritt 3
</button>
</div>
</div>
{{ form_rest(form) }}
{{ form_end(form) }}
{% endblock %}
{# Swapped into #booking-form on every htmx refresh #}
{% block booking_form %}
{# Flash messages - must be inside the swapped region to be displayed #}
{% include '_partials/_flashes.html.twig' %}
{# Validation errors #} {# Validation errors #}
{% from '_partials/_validation_errors.html.twig' import validation_alert %} {% from '_partials/_validation_errors.html.twig' import validation_alert %}
@@ -201,23 +228,4 @@
{% endif %} {% endif %}
</div>
</div>
{% endblock %}
</div>
<div class="shrink-0 bg-primary-dark px-4 lg:px-8 py-2 lg:py-4 z-20">
<div class="flex items-center justify-between">
<a href="{{ path('app_groups_booking_step_1') }}" class="button button--secondary">
Zurück
</a>
<button type="submit" class="button button--primary">
Weiter zu Schritt 3
</button>
</div>
</div>
{{ form_rest(form) }}
{{ form_end(form) }}
{% endblock %} {% endblock %}
+1 -1
View File
@@ -36,7 +36,7 @@
{% include 'groups/booking/_pagination.html.twig' with { 'current_step': 3 } %} {% include 'groups/booking/_pagination.html.twig' with { 'current_step': 3 } %}
</div> </div>
<div id="participant-form" class="flex-1 overflow-y-auto px-4 lg:px-8 py-8"> <div id="booking-form" class="flex-1 overflow-y-auto px-4 lg:px-8 py-8">
<h2 class="pb-4"> <h2 class="pb-4">
Persönliche Daten Persönliche Daten
</h2> </h2>