Although Symfony provides a nice integration of selecting dates, we have extended the functionality a bit.
When passing the datepicker
-option as true, a nice date picker will be shown
in the form.
<?php
// ...
$form = $this->createFormBuilder()
->add(
'date',
DateType::class,
[
'data' => new DateTime(),
'widget' => 'single_text',
'datepicker' => true,
'minimum_date' => DateTime::createFromFormat('Y/m/d', '2017/08/14'),
'maximum_date' => DateTime::createFromFormat('Y/m/d', '2017/08/30'),
]
)
// ...
As you will see this will only work when the widget
-option has the value
single_text
.
In most case you will have some constraints to the date, and this should be reflected in the UI.
Passing the minimum_date
and / or maximum_date
limits the selectable dates.
A more detailed example is available in the FrameworkExampleBundle.