Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dd2f830

Browse files
committed
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 ------- df19155 [Form] Added options for separate date/time labels in DateTimeType.
2 parents 6198223 + df19155 commit dd2f830

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Symfony/Component/Form/Extension/Core/Type/DateTimeType.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,18 @@ public function buildForm(FormBuilderInterface $builder, array $options)
137137
$dateOptions['widget'] = $options['date_widget'];
138138
}
139139

140+
if (null !== $options['date_label']) {
141+
$dateOptions['label'] = $options['date_label'];
142+
}
143+
140144
if (null !== $options['time_widget']) {
141145
$timeOptions['widget'] = $options['time_widget'];
142146
}
143147

148+
if (null !== $options['time_label']) {
149+
$timeOptions['label'] = $options['time_label'];
150+
}
151+
144152
if (null !== $options['date_format']) {
145153
$dateOptions['format'] = $options['date_format'];
146154
}
@@ -235,6 +243,8 @@ public function configureOptions(OptionsResolver $resolver)
235243
// this option.
236244
'data_class' => null,
237245
'compound' => $compound,
246+
'date_label' => null,
247+
'time_label' => null,
238248
));
239249

240250
// Don't add some defaults in order to preserve the defaults

0 commit comments

Comments
 (0)