feat: improved tooltip and readonly handling of checkboxes

This commit is contained in:
Björn Fromme
2025-03-27 10:38:58 +01:00
parent 4873465232
commit fe20b6ab2b
+9 -10
View File
@@ -65,18 +65,13 @@
{%- endblock textarea_widget -%}
{%- block checkbox_widget -%}
{%- set attr = attr|filter((v, k) => k != 'tooltip') -%}
{%- set attr = attr|merge({'class': (attr.class|default('') ~ ' form-checkbox')|trim }) -%}
{%- if errors|length -%}
{%- set attr = attr|merge({'class': attr.class|default('') ~ ' form-checkbox--has-error' }) -%}
{%- endif -%}
{%- set tooltip = null -%}
{%- if attr.tooltip is defined -%}
{%- set tooltip = attr.tooltip -%}
{%- set attr = attr|filter((v, k) => k != 'tooltip') -%}
{%- endif -%}
<div{% if tooltip is not null %} {{ stimulus_controller('tooltip', { 'content': tooltip }) }}{% endif %}>
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
</div>
<input type="checkbox" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %} />
{%- endblock checkbox_widget -%}
{%- block radio_widget -%}
@@ -95,13 +90,17 @@
{%- endblock radio_widget -%}
{% block checkbox_row %}
<div class="{{ html_classes('relative flex items-start', { 'cursor-not-allowed': form.vars.attr.readonly is defined }) }}">
{%- set tooltip = null -%}
{%- if form.vars.attr.tooltip is defined -%}
{%- set tooltip = form.vars.attr.tooltip -%}
{%- endif -%}
<div class="{{ html_classes('relative flex items-start', { 'cursor-not-allowed': form.vars.attr.readonly is defined }) }}"{% if tooltip is not null %} {{ stimulus_controller('tooltip', { 'content': tooltip }) }}{% endif %}>
<div class="flex h-6 items-center">
{{ form_widget(form) }}
</div>
<div class="{{ html_classes('ml-1 leading-6', { 'text-red-500': errors|length }) }}">
<label for="{{ form.vars.id }}">
{{ form.vars.label }}
<label for="{{ form.vars.id }}" class="{{ html_classes({ 'pointer-events-none': form.vars.attr.readonly is defined }) }}">
{{ form.vars.label | raw }}
</label>
{{- form_errors(form) -}}
</div>