8000 [Twig] daisyUI form layout by Oviglo · Pull Request #60334 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Twig] daisyUI form layout #60334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: 7.4
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
file input + errors
  • Loading branch information
Oviglo committed May 14, 2025
commit 0e1b09946463c4a8f9e3013e6ad128882e66181b
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
{% use 'tailwind_2_layout.html.twig' %}
{% use 'form_div_layout.html.twig' %}

{%- block form_row -%}
{%- set row_attr = row_attr|merge({ class: row_attr.class|default(row_class|default('flex flex-col mb-6')) }) -%}
{{- parent() -}}
{%- endblock form_row -%}

{%- block form_errors -%}
{%- set attr = attr|merge({class: (attr.class|default('text-error'))|trim}) -%}
{%- block widget_attributes -%}
{%- set attr = attr|merge({ class: attr.class|default(widget_class|default('mt-1 w-full')) ~ (errors|length ? ' ' ~ widget_errors_class|default('input-error')) }) -%}
{{- parent() -}}
{%- endblock widget_attributes -%}

{%- block form_errors -%}
{%- if errors|length > 0 -%}
<ul>
{%- for error in errors -%}
<li class="{{ error_item_class|default('text-error') }}">{{ error.message }}</li>
{%- endfor -%}
</ul>
{%- endif -%}
{%- endblock form_errors -%}

{%- block form_help -%}
{%- set attr = attr|merge({class: (attr.class|default('text-sm text-neutral'))|trim}) -%}
{%- set help_attr = help_attr|merge({class: (help_attr.class|default('mt-1 label'))|trim}) -%}
{{- parent() -}}
{%- endblock form_help -%}

Expand Down Expand Up @@ -46,7 +56,7 @@
{%- set row_attr = row_attr|merge({ class: row_attr.class|default(row_class|default('mb-6')) }) -%}
{%- set widget_attr = {} -%}
{%- if help is not empty -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
{%- set widget_attr = {attr: {'aria-describedby': id ~"_help"} } -%}
{%- endif -%}
<div{% with {attr: row_attr} %}{{ block('attributes') }}{% endwith %}>
{{- form_errors(form) -}}
Expand All @@ -59,12 +69,12 @@
{%- endblock checkbox_row -%}

{%- block checkbox_widget -%}
{%- set widget_class = widget_class|default('checkbox') -%}
{%- set widget_class = (widget_class|default('checkbox') ~ (errors|length ? ' checkbox-error')) -%}
{{- parent() -}}
{%- endblock checkbox_widget -%}

{% block radio_widget -%}
{%- set widget_class = widget_class|default('radio') -%}
{%- set widget_class = (widget_class|default('radio') ~ (errors|length ? ' radio-error')) -%}
{{- parent() -}}
{%- endblock radio_widget %}

Expand All @@ -84,8 +94,14 @@
{{- block('form_widget_simple') -}}
{%- endblock range_widget %}

{%- block file_widget -%}
{% set type = type|default('file') %}
{%- set widget_class = (widget_class|default('file-input mt-2') ~ (errors|length ? ' file-input-error')) -%}
{{- block('form_widget_simple') -}}
{%- endblock file_widget %}

{% block form_widget_simple -%}
{%- if type is not defined or type not in ['hidden', 'range'] %}
{%- if type is not defined or type not in ['hidden', 'range', 'file'] %}
{%- set widget_class = ' input mt-2' %}
{%- set attr = attr|merge({class: (attr.class|default('') ~ widget_class)|trim}) -%}
{% endif -%}
Expand Down
0