Commit c36395f
committed
feature #63631 [Form] Add
This PR was merged into the 8.1 branch.
Discussion
----------
[Form] Add `labels` option to DateType to customize year/month/day sub-field labels
| Q | A
| ------------- | ---
| Branch? | 8.1
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Issues | Fix #59825
| License | MIT
**Problem**
When using `DateType` (or `BirthdayType`) with `widget: choice` or `widget: text`, the year/month/day sub-field labels are auto-generated from the field names ("Year", "Month", "Day") with no way to customize or disable them.
**Solution**
Add a `labels` option to `DateType`, following the same pattern as the existing `labels` option in `DateIntervalType`.
Accepted values:
- `[]` (default) - auto-generates labels from field names
- `array` - per-field control, unspecified fields fall back to null
Usage:
```
$builder->add('dueDate', DateType::class, [
'widget' => 'choice',
'labels' => [
'year' => 'Birth year',
'month' => 'Birth month',
'day' => 'Birth day',
],
]);
// partial array — only override what you need
$builder->add('dueDate', DateType::class, [
'widget' => 'choice',
'labels' => [
'year' => 'Birth year',
],
]);
```
Since BirthdayType extends DateType, it inherits this option automatically.
Commits
-------
814c851 [Form] Add `labels` option to DateType to customize year/month/day sub-field labelslabels option to DateType to customize year/month/day sub-field labels (guillaumeVDP)3 files changed
+46Lines changed: 46 additions & 0 deletions
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- src/Symfony/Component/Form
- Extension/Core/Type
- Tests/Extension/Core/Type
Expand file treeCollapse file tree
Open diff view settings
Collapse file
src/Symfony/Component/Form/CHANGELOG.md
Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/CHANGELOG.md+1Lines changed: 1 addition & 0 deletions
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
10 | 10 | |
11 | 11 | |
12 | 12 | |
| 13 | + |
13 | 14 | |
14 | 15 | |
15 | 16 | |
|
Collapse file
src/Symfony/Component/Form/Extension/Core/Type/DateType.php
Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/DateType.php+12Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
147 | 147 | |
148 | 148 | |
149 | 149 | |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | + |
150 | 154 | |
151 | 155 | |
152 | 156 | |
| ||
269 | 273 | |
270 | 274 | |
271 | 275 | |
| 276 | + |
| 277 | + |
| 278 | + |
| 279 | + |
| 280 | + |
272 | 281 | |
273 | 282 | |
274 | 283 | |
| ||
282 | 291 | |
283 | 292 | |
284 | 293 | |
| 294 | + |
285 | 295 | |
286 | 296 | |
287 | 297 | |
| ||
301 | 311 | |
302 | 312 | |
303 | 313 | |
| 314 | + |
| 315 | + |
304 | 316 | |
305 | 317 | |
306 | 318 | |
|
Collapse file
src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php
Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php+33Lines changed: 33 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
1204 | 1204 | |
1205 | 1205 | |
1206 | 1206 | |
| 1207 | + |
| 1208 | + |
| 1209 | + |
| 1210 | + |
| 1211 | + |
| 1212 | + |
| 1213 | + |
| 1214 | + |
| 1215 | + |
| 1216 | + |
| 1217 | + |
| 1218 | + |
| 1219 | + |
| 1220 | + |
| 1221 | + |
| 1222 | + |
| 1223 | + |
| 1224 | + |
| 1225 | + |
| 1226 | + |
| 1227 | + |
| 1228 | + |
| 1229 | + |
| 1230 | + |
| 1231 | + |
| 1232 | + |
| 1233 | + |
| 1234 | + |
| 1235 | + |
| 1236 | + |
| 1237 | + |
| 1238 | + |
| 1239 | + |
1207 | 1240 | |
1208 | 1241 | |
1209 | 1242 | |
|
0 commit comments