New in Symfony 6.3: Form Improvements
The Form component is one of the most solid components of Symfony. It’s so
mature and stable that it no longer adds many new features. However, in
Symfony 6.3 we improved it with some minor new features.
Improved Handling of Seconds in Date/Time Fields
The with_seconds option of fields like DateTimeType and TimeType
tells Symfony whether to include seconds in the input. When the form field
doesn’t have any data, this option shows/hides the seconds.
However, when the field has some data, the seconds are always shown because of
how the date/time values are handled.
In Symfony 6.3, this option will always work as expected regardless of the field
HTML5 Date/Time Widgets by Default
The html5 option of date fields tells Symfony to use a native HTML5 widget
to render date/time fields. However, setting it to true is not enough to see
those native widgets. You also have to set the widget option to single_text.
However, because of Symfony Backward Compatibility Promise we can’t just change
the default value of that widget option because it’d break some applications.
Instead, in Symfony 6.3 we’re deprecating not setting a value for this option.
This way, all applications must make a conscious decision about which value to
use in that widget option.
This will allow us to make single_text the default value of widget in
Symfony 7.0 (released in November 2023) to completely finish this improvement.
Choice Placeholder Attributes
The ChoiceType field and all its related fields (Country, Currency, Locale,
Language, Entity, etc.) define a placeholder option to display the common
„Choose an option“ empty option at the top of the list of options.
In Symfony 6.3 we’re adding a new placeholder_attr option so you can
customize this placeholder (e.g. to display it disabled, to add HTML attributes
to it, etc.):
$builder->add(‚fruits‘, ChoiceType::class, [
‚placeholder‘ => ‚…‘,
‚placeholder_attr‘ => [
‚title‘ => ‚Choose an option‘,
‚disabled‘ => true,
‚data-some-custom-attribute‘ => ‚foo‘,