8000 file input + errors · symfony/symfony@0e1b099 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e1b099

Browse files
committed
file input + errors
1 parent 557fba4 commit 0e1b099

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/Symfony/Bridge/Twig/Resources/views/Form/daisyui_5_layout.html.twig

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1-
{% use 'tailwind_2_layout.html.twig' %}
1+
{% use 'form_div_layout.html.twig' %}
22

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

8-
{%- block form_errors -%}
9-
{%- set attr = attr|merge({class: (attr.class|default('text-error'))|trim}) -%}
8+
{%- block widget_attributes -%}
9+
{%- set attr = attr|merge({ class: attr.class|default(widget_class|default('mt-1 w-full')) ~ (errors|length ? ' ' ~ widget_errors_class|default('input-error')) }) -%}
1010
{{- parent() -}}
11+
{%- endblock widget_attributes -%}
12+
13+
{%- block form_errors -%}
14+
{%- if errors|length > 0 -%}
15+
<ul>
16+
{%- for error in errors -%}
17+
<li class="{{ error_item_class|default('text-error') }}">{{ error.message }}</li>
18+
{%- endfor -%}
19+
</ul>
20+
{%- endif -%}
1121
{%- endblock form_errors -%}
1222

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

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

6171
{%- block checkbox_widget -%}
62-
{%- set widget_class = widget_class|default('checkbox') -%}
72+
{%- set widget_class = (widget_class|default('checkbox') ~ (errors|length ? ' checkbox-error')) -%}
6373
{{- parent() -}}
6474
{%- endblock checkbox_widget -%}
6575

6676
{% block radio_widget -%}
67-
{%- set widget_class = widget_class|default('radio') -%}
77+
{%- set widget_class = (widget_class|default('radio') ~ (errors|length ? ' radio-error')) -%}
6878
{{- parent() -}}
6979
{%- endblock radio_widget %}
7080

@@ -84,8 +94,14 @@
8494
{{- block('form_widget_simple') -}}
8595
{%- endblock range_widget %}
8696

97+
{%- block file_widget -%}
98+
{% set type = type|default('file') %}
99+
{%- set widget_class = (widget_class|default('file-input mt-2') ~ (errors|length ? ' file-input-error')) -%}
100+
{{- block('form_widget_simple') -}}
101+
{%- endblock file_widget %}
102+
87103
{% block form_widget_simple -%}
88-
{%- if type is not defined or type not in ['hidden', 'range'] %}
104+
{%- if type is not defined or type not in ['hidden', 'range', 'file'] %}
89105
{%- set widget_class = ' input mt-2' %}
90106
{%- set attr = attr|merge({class: (attr.class|default('') ~ widget_class)|trim}) -%}
91107
{% endif -%}

0 commit comments

Comments
 (0)
0