feat: trigger form refresh for dob when completely entered only

This commit is contained in:
Björn Fromme
2026-01-13 15:37:05 +01:00
parent f942600dd8
commit 3c61e7eaf3
2 changed files with 82 additions and 1 deletions
+23 -1
View File
@@ -253,8 +253,24 @@
'year': 'Jahr'
} -%}
{%- set field_order = ['day', 'month', 'year'] -%}
{# Check if HTMX attributes are present - if so, use birthday controller for deferred triggering #}
{%- set has_htmx = attr['hx-trigger'] is defined -%}
{%- set htmx_attrs = {} -%}
{%- if has_htmx -%}
{# Extract HTMX attributes and replace trigger with custom event #}
{%- set htmx_attrs = {
'hx-trigger': 'birthday:complete',
'hx-post': attr['hx-post']|default(''),
'hx-target': attr['hx-target']|default('#main-content'),
'hx-swap': attr['hx-swap']|default('innerHTML')
} -%}
{# Remove HTMX attrs from main attr to avoid duplication #}
{%- set attr = attr|filter((v, k) => k not in ['hx-trigger', 'hx-post', 'hx-target', 'hx-swap']) -%}
{%- endif -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' flex items-center space-x-2')|trim}) -%}
<div {{ block('widget_container_attributes') }}>
<div {{ block('widget_container_attributes') }}{% if has_htmx %} {{ stimulus_controller('birthday') }}{% for key, value in htmx_attrs %} {{ key }}="{{ value }}"{% endfor %}{% endif %}>
{%- for field_name in field_order -%}
{%- set child = form[field_name] -%}
{%- set child_attr = child.vars.attr|default({}) -%}
@@ -262,6 +278,12 @@
'placeholder': placeholders[field_name],
'class': (child_attr.class|default('') ~ ' form-field')|trim
}) -%}
{%- if has_htmx -%}
{%- set child_attr = child_attr|merge({
'data-birthday-target': field_name,
'data-action': 'change->birthday#check'
}) -%}
{%- endif -%}
{{- form_widget(child, {'attr': child_attr}) -}}
{% if not loop.last %}