feature #21002 [Form] Added options for separate date/time labels in DateTimeType. (mktcode)
This PR was squashed before being merged into the 4.2-dev branch (closes #21002).
Discussion
----------
[Form] Added options for separate date/time labels in DateTimeType.
If your render date and time separately you need options for each label.
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| License | MIT
Let's say you have the following form field:
```
$builder
->add('start', DateTimeType::class, [
'date_widget' => 'single_text',
...
])
...
```
Then you can render the date and time widgets/rows/etc. separately:
```
<div>{{ form_row(form.start.date) }}</div>
<div>{{ form_row(form.start.time) }}</div>
```
But you can't provide labels for each, so what is displayed is just the uppercased field name ("Date" and "Time").
This PR adds 'date_label' and 'time_label' options, so you can do:
```
$builder
->add('start', DateTimeType::class, [
'date_widget' => 'single_text',
'date_label' => 'The Start Date',
'time_label' => 'The Start Time',
...
])
...
```
Commits
-------
df191552b4
[Form] Added options for separate date/time labels in DateTimeType.
This commit is contained in:
commit
dd2f83012f
@ -137,10 +137,18 @@ class DateTimeType extends AbstractType
|
|||||||
$dateOptions['widget'] = $options['date_widget'];
|
$dateOptions['widget'] = $options['date_widget'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (null !== $options['date_label']) {
|
||||||
|
$dateOptions['label'] = $options['date_label'];
|
||||||
|
}
|
||||||
|
|
||||||
if (null !== $options['time_widget']) {
|
if (null !== $options['time_widget']) {
|
||||||
$timeOptions['widget'] = $options['time_widget'];
|
$timeOptions['widget'] = $options['time_widget'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (null !== $options['time_label']) {
|
||||||
|
$timeOptions['label'] = $options['time_label'];
|
||||||
|
}
|
||||||
|
|
||||||
if (null !== $options['date_format']) {
|
if (null !== $options['date_format']) {
|
||||||
$dateOptions['format'] = $options['date_format'];
|
$dateOptions['format'] = $options['date_format'];
|
||||||
}
|
}
|
||||||
@ -235,6 +243,8 @@ class DateTimeType extends AbstractType
|
|||||||
// this option.
|
// this option.
|
||||||
'data_class' => null,
|
'data_class' => null,
|
||||||
'compound' => $compound,
|
'compound' => $compound,
|
||||||
|
'date_label' => null,
|
||||||
|
'time_label' => null,
|
||||||
));
|
));
|
||||||
|
|
||||||
// Don't add some defaults in order to preserve the defaults
|
// Don't add some defaults in order to preserve the defaults
|
||||||
|
Reference in New Issue
Block a user