@@ -79,31 +79,67 @@ If you prefer to apply the Bootstrap styles on a form to form basis, include the
79
79
80
80
.. _reference-forms-bootstrap-error-messages :
81
81
82
- General
83
- -------
82
+ .. note ::
84
83
85
- By default, all inputs are rendered with the ``mb-3 `` class on their container.
84
+ By default, all inputs are rendered with the ``mb-3 `` class on their container.
85
+ If you override the `row_attr ` class option, the ``mb-3 `` will be override too
86
+ and you will need to explicitly add it.
86
87
87
88
Error Messages
88
89
--------------
89
90
90
- Form errors are rendered **inside ** the ``<label> `` element to make sure there
91
- is a strong connection between the error and its ``<input> ``, as required by the
92
- `WCAG 2.0 standard `_. To achieve this, ``form_errors() `` is called by
93
- ``form_label() `` internally. If you call to ``form_errors() `` in your template,
94
- you'll get the error messages displayed *twice *.
91
+ Unlike the Bootstrap 4 template, errors are rendered **after ** the ``input `` element.
92
+ However, this still make a strong connection between the error and its ``<input> ``, as
93
+ required by the `WCAG 2.0 standard `_.
95
94
96
95
Checkboxes and Radios
97
96
---------------------
98
97
99
98
For a checkbox/radio field, calling ``form_label() `` doesn't render anything.
100
99
Due to Bootstrap internals, the label is already rendered by ``form_widget() ``.
101
100
101
+ Inline Checkboxes and Radios
102
+ ----------------------------
103
+
104
+ If you want to render your checkboxes or radios fields `inline `_, you can add
105
+ the `checkbox-inline ` or `radio-inline ` class, depending of your Symfony Form
106
+ type or `ChoiceType ` configuration, to the label class.
107
+
108
+ .. configuration-block ::
109
+
110
+ .. code-block :: php
111
+
112
+ $builder
113
+ ->add('myCheckbox', CheckboxType::class, [
114
+ 'label_attr' => [
115
+ 'class' => '`checkbox-inline',
116
+ ],
117
+ ])
118
+ ->add('myRadio', RadioType::class, [
119
+ 'label_attr' => [
120
+ 'class' => 'radio-inline',
121
+ ],
122
+ ]);
123
+
124
+ .. code-block :: twig
125
+
126
+ {{ form_row(form.myCheckbox, {
127
+ label_attr: {
128
+ class: 'checkbox-inline'
129
+ }
130
+ }) }}
131
+
132
+ {{ form_row(form.myRadio, {
133
+ label_attr: {
134
+ class: 'radio-inline'
135
+ }
136
+ }) }}
137
+
102
138
Switches
103
139
________
104
140
105
- Bootstrap 5 allow to render checkboxes as "`switches `_". You can enable that on your
106
- Symfony Form ``CheckboxType `` by adding the ``checkbox-switch `` class to the label:
141
+ Bootstrap 5 allow to render checkboxes as "`switches `_". You can enable this feature
142
+ on your Symfony Form ``CheckboxType `` by adding the ``checkbox-switch `` class to the label:
107
143
108
144
.. configuration-block ::
109
145
@@ -123,6 +159,54 @@ Symfony Form ``CheckboxType`` by adding the ``checkbox-switch`` class to the lab
123
159
}
124
160
}) }}
125
161
162
+ .. tip ::
163
+
164
+ You can also render your switches inline by simply adding the ``checkbox-inline `` class
165
+ on the ``label_attr `` option.
166
+
167
+ .. code-block :: php
168
+
169
+ ...
170
+ 'label_attr' => [
171
+ 'class' => '`checkbox-inline checkbox-switch',
172
+ ],
173
+ ...
174
+
175
+ .. caution ::
176
+
177
+ Switches only worked with **checkbox **.
178
+
179
+ Input group
180
+ ___________
181
+
182
+ To create `input group `_ in your Symfony Form, simply add the `input-group ` class
183
+ to the ``row_attr `` option.
184
+
185
+ .. configuration-block ::
186
+
187
+ .. code-block :: php
188
+
189
+ $builder->add('email', CheckboxType::class, [
190
+ 'label' => '@',
191
+ 'row_attr' => [
192
+ 'class' => 'input-group',
193
+ ],
194
+ ]);
195
+
196
+ .. code-block :: twig
197
+
198
+ {{ form_row(form.email, {
199
+ label: '@',
200
+ row_attr: {
201
+ class: 'input-group'
202
+ }
203
+ }) }}
204
+
205
+ .. caution ::
206
+
207
+ If you have filled in the `help ` option of your form, it will also be rendered
208
+ as part of the group.
209
+
126
210
Floating labels
127
211
---------------
128
212
@@ -156,6 +240,11 @@ of your form type.
156
240
}
157
241
}) }}
158
242
243
+ .. caution ::
244
+
245
+ You **must ** provide a ``label `` and a ``placeholder `` to make floating labels
246
+ works properly.
247
+
159
248
Accessibility
160
249
-------------
161
250
@@ -168,5 +257,7 @@ standard, but it does mean that you have come far in your work to create a desig
168
257
for **all ** users.
169
258
170
259
.. _`WCAG 2.0 standard` : https://www.w3.org/TR/WCAG20/
260
+ .. _`inline` : https://getbootstrap.com/docs/5.0/forms/checks-radios/#inline
171
261
.. _`switches` : https://getbootstrap.com/docs/5.0/forms/checks-radios/#switches
262
+ .. _`input group` : https://getbootstrap.com/docs/5.0/forms/input-group/
172
263
.. _`floating label` : https://getbootstrap.com/docs/5.0/forms/floating-labels/
0 commit comments