|
3 | 3 | {# Widgets #}
|
4 | 4 |
|
5 | 5 | {% block money_widget -%}
|
6 |
| - {% if not valid %} |
7 |
| - {% set group_class = ' form-control is-invalid' %} |
8 |
| - {% set valid = true %} |
9 |
| - {% endif %} |
10 |
| - {{- parent() -}} |
| 6 | + {%- set prepend = not (money_pattern starts with '{{') -%} |
| 7 | + {%- set append = not (money_pattern ends with '}}') -%} |
| 8 | + {%- if prepend or append -%} |
| 9 | + <div class="input-group{{ group_class|default('') }}"> |
| 10 | + {%- if prepend -%} |
| 11 | + <div class="input-group-prepend"> |
| 12 | + <span class="input-group-text">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span> |
| 13 | + </div> |
| 14 | + {%- endif -%} |
| 15 | + {{- block('form_widget_simple') -}} |
| 16 | + {%- if append -%} |
| 17 | + <div class="input-group-append"> |
| 18 | + <span class="input-group-text">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span> |
| 19 | + </div> |
| 20 | + {%- endif -%} |
| 21 | + </div> |
| 22 | + {%- else -%} |
| 23 | + {{- block('form_widget_simple') -}} |
| 24 | + {%- endif -%} |
11 | 25 | {%- endblock money_widget %}
|
12 | 26 |
|
13 | 27 | {% block datetime_widget -%}
|
|
39 | 53 | {% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) -%}
|
40 | 54 | {% set valid = true %}
|
41 | 55 | {%- endif -%}
|
42 |
| - |
43 | 56 | {%- if widget == 'single_text' -%}
|
44 | 57 | {{- block('form_widget_simple') -}}
|
45 | 58 | {%- else -%}
|
|
80 | 93 | <div class="input-group{{ not valid ? ' form-control is-invalid' }}">
|
81 | 94 | {% set valid = true %}
|
82 | 95 | {{- block('form_widget_simple') -}}
|
83 |
| - <span class="input-group-addon">%</span> |
| 96 | + <div class="input-group-append"> |
| 97 | + <span class="input-group-text">%</span> |
| 98 | + </div> |
84 | 99 | </div>
|
85 | 100 | {%- endblock percent_widget %}
|
86 | 101 |
|
|
93 | 108 |
|
94 | 109 | {%- block widget_attributes -%}
|
95 | 110 | {%- if not valid %}
|
96 |
| - {% set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) %} |
| 111 | + {% set attr = attr|merge({class: (attr.class|default('') ~ ' is-invalid')|trim}) %} |
97 | 112 | {% endif -%}
|
98 | 113 | {{ parent() }}
|
99 | 114 | {%- endblock widget_attributes -%}
|
|
105 | 120 |
|
106 | 121 | {% block checkbox_widget -%}
|
107 | 122 | {%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
|
108 |
| - {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%} |
109 |
| - {% if 'checkbox-inline' in parent_label_class %} |
110 |
| - {{- form_label(form, null, { widget: parent() }) -}} |
111 |
| - {% elseif 'form-check-inline' in parent_label_class %} |
112 |
| - <div class="form-check{{ not valid ? ' form-control is-invalid' }} form-check-inline"> |
| 123 | + {%- if 'checkbox-custom' in parent_label_class -%} |
| 124 | + {%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%} |
| 125 | + <div class="custom-control custom-checkbox{{ 'checkbox-inline' in parent_label_class ? ' custom-control-inline' }}"> |
113 | 126 | {{- form_label(form, null, { widget: parent() }) -}}
|
114 | 127 | </div>
|
115 |
| - {% else -%} |
116 |
| - <div class="form-check{{ not valid ? ' form-control is-invalid' }}"> |
| 128 | + {%- else -%} |
| 129 | + {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%} |
| 130 | + <div class="form-check{{ 'checkbox-inline' in parent_label_class ? ' form-check-inline' }}"> |
117 | 131 | {{- form_label(form, null, { widget: parent() }) -}}
|
118 | 132 | </div>
|
119 | 133 | {%- endif -%}
|
120 | 134 | {%- endblock checkbox_widget %}
|
121 | 135 |
|
122 | 136 | {% block radio_widget -%}
|
123 | 137 | {%- set parent_label_class = parent_label_class|default(label_attr.class|default('')) -%}
|
124 |
| - {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%} |
125 |
| - {%- if 'radio-inline' in parent_label_class -%} |
126 |
| - {{- form_label(form, null, { widget: parent() }) -}} |
| 138 | + {%- if 'radio-custom' in parent_label_class -%} |
| 139 | + {%- set attr = attr|merge({class: (attr.class|default('') ~ ' custom-control-input')|trim}) -%} |
| 140 | + <div class="custom-control custom-radio{{ 'radio-inline' in parent_label_class ? ' custom-control-inline' }}"> |
| 141 | + {{- form_label(form, null, { widget: parent() }) -}} |
| 142 | + </div> |
127 | 143 | {%- else -%}
|
128 |
| - <div class="form-check{{ not valid ? ' form-control is-invalid' }}"> |
| 144 | + {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-check-input')|trim}) -%} |
| 145 | + <div class="form-check{{ 'radio-inline' in parent_label_class ? ' form-check-inline' }}"> |
129 | 146 | {{- form_label(form, null, { widget: parent() }) -}}
|
130 | 147 | </div>
|
131 | 148 | {%- endif -%}
|
132 | 149 | {%- endblock radio_widget %}
|
133 | 150 |
|
134 | 151 | {% block choice_widget_expanded -%}
|
135 |
| - {% if '-inline' in label_attr.class|default('') -%} |
| 152 | + <div {{ block('widget_container_attributes') }}> |
136 | 153 | {%- for child in form %}
|
137 | 154 | {{- form_widget(child, {
|
138 | 155 | parent_label_class: label_attr.class|default(''),
|
139 | 156 | translation_domain: choice_translation_domain,
|
140 | 157 | valid: valid,
|
141 | 158 | }) -}}
|
142 | 159 | {% endfor -%}
|
143 |
| - {%- else -%} |
144 |
| - {%- if not valid -%} |
145 |
| - {%- set attr = attr|merge({class: (attr.class|default('') ~ ' form-control is-invalid')|trim}) %} |
146 |
| - {%- endif -%} |
147 |
| - <div {{ block('widget_container_attributes') }}> |
148 |
| - {%- for child in form %} |
149 |
| - {{- form_widget(child, { |
150 |
| - parent_label_class: label_attr.class|default(''), |
151 |
| - translation_domain: choice_translation_domain, |
152 |
| - valid: true, |
153 |
| - }) -}} |
154 |
| - {% endfor -%} |
155 |
| - </div> |
156 |
| - {%- endif %} |
| 160 | + </div> |
157 | 161 | {%- endblock choice_widget_expanded %}
|
158 | 162 |
|
159 | 163 | {# Labels #}
|
|
162 | 166 | {% if label is not same as(false) -%}
|
163 | 167 | {%- if compound is defined and compound -%}
|
164 | 168 | {%- set element = 'legend' -%}
|
165 |
| - {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-form-legend')|trim}) -%} |
| 169 | + {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-form-label')|trim}) -%} |
166 | 170 | {%- else -%}
|
167 | 171 | {%- set label_attr = label_attr|merge({for: id, class: (label_attr.class|default('') ~ ' form-control-label')|trim}) -%}
|
168 | 172 | {%- endif -%}
|
|
179 | 183 | {% set label = name|humanize %}
|
180 | 184 | {%- endif -%}
|
181 | 185 | {%- endif -%}
|
182 |
| - <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}{% block form_label_errors %}{{- form_errors(form) -}}{% endblock form_label_errors %}</{{ element|default('label') }}> |
| 186 | + <{{ element|default('label') }}{% if label_attr %}{% with { attr: label_attr } %}{{ block('attributes') }}{% endwith %}{% endif %}>{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}{{- form_errors(form) -}}</{{ element|default('label') }}> |
183 | 187 | {%- endif -%}
|
184 | 188 | {%- endblock form_label %}
|
185 | 189 |
|
186 | 190 | {% block checkbox_radio_label -%}
|
187 | 191 | {#- Do not display the label if widget is not defined in order to prevent double label rendering -#}
|
188 | 192 | {%- if widget is defined -%}
|
189 |
| - {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-check-label')|trim}) -%} |
| 193 | + {%- if parent_label_class is defined and ('checkbox-custom' in parent_label_class or 'radio-custom' in parent_label_class) -%} |
| 194 | + {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' custom-control-label')|trim}) -%} |
| 195 | + {%- else %} |
| 196 | + {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' form-check-label')|trim}) -%} |
| 197 | + {%- endif %} |
| 198 | + {%- if not compound -%} |
| 199 | + {% set label_attr = label_attr|merge({'for': id}) %} |
| 200 | + {%- endif -%} |
190 | 201 | {%- if required -%}
|
191 | 202 | {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) -%}
|
192 | 203 | {%- endif -%}
|
193 | 204 | {%- if parent_label_class is defined -%}
|
194 |
| - {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|trim}) -%} |
| 205 | + {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|replace({'checkbox-inline': '', 'radio-inline': '', 'checkbox-custom': '', 'radio-custom': ''})|trim}) -%} |
195 | 206 | {%- endif -%}
|
196 | 207 | {%- if label is not same as(false) and label is empty -%}
|
197 | 208 | {%- if label_format is not empty -%}
|
|
203 | 214 | {%- set label = name|humanize -%}
|
204 | 215 | {%- endif -%}
|
205 | 216 | {%- endif -%}
|
| 217 | + |
| 218 | + {{ widget|raw }} |
206 | 219 | <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
|
207 |
| - {{- widget|raw }} {{ label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}} |
| 220 | + {{- label is not same as(false) ? (translation_domain is same as(false) ? label : label|trans({}, translation_domain)) -}} |
| 221 | + {{- form_errors(form) -}} |
208 | 222 | </label>
|
209 | 223 | {%- endif -%}
|
210 | 224 | {%- endblock checkbox_radio_label %}
|
|
225 | 239 |
|
226 | 240 | {% block form_errors -%}
|
227 | 241 | {%- if errors|length > 0 -%}
|
228 |
| - <div class="{% if form is not rootform %}invalid-feedback{% else %}alert alert-danger{% endif %}"> |
229 |
| - <ul class="list-unstyled mb-0"> |
230 |
| - {%- for error in errors -%} |
231 |
| - <li>{{ error.message }}</li> |
232 |
| - {%- endfor -%} |
233 |
| - </ul> |
234 |
| - </div> |
| 242 | + <div class="{% if form is not rootform %}invalid-feedback d-block{% else %}alert alert-danger{% endif %}"> |
| 243 | + <ul class="list-unstyled mb-0"> |
| 244 | + {%- for error in errors -%} |
| 245 | + <li>{{ error.message }}</li> |
| 246 | + {%- endfor -%} |
| 247 | + </ul> |
| 248 | + </div> |
235 | 249 | {%- endif %}
|
236 | 250 | {%- endblock form_errors %}
|
0 commit comments