New in Symfony 2.8: Form improvements
Added a new Range
form type¶
Contributed by
Joshua Thijssen
in #12067.
The HTML5 range
form field was missing from the list of built-in Symfony
Form types. This new type is rendered as a slider in browsers that support HTML5
form controls. Use the min
and max
attributes to constraint the selectable
values:
1 2 3 | $builder->add('rating', 'Symfony\Component\Form\Extension\Core\Type\RangeType', [
'attr' => ['min' => 0, 'max' => 10]
]);
|
Added the prototype_data
option to collection type¶
Contributed by
Kristen Gilden
in #12314.
Forms that contain collections allow to customize the HTML used to add new items
(prototype option) and the name of the placeholder used in that template
(prototype_name option). Symfony 2.8 allows to also define the default data
of each new collection row thanks to the prototype_data
option:
1 2 3 4 5 | $builder->add('tags', 'Symfony\Component\Form\Extension\Core\Type\CollectionType', [
// ...
'by_reference' => false,
'prototype_data' => '...',
]);
|
Allowed to return null
for query_builder
¶
Contributed by
Thomas Lallement
in #13990.
Sometimes it's useful to display an empty list of entries for entity
form types.
In Symfony 2.7 you needed to pass an empty list to its choices
option. In
Symfony 2.8, you can return null
in the query_builder
closure to display
an empty list of entries:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | $event->getForm()->add('events', 'Symfony\Component\Form\Extension\Core\Type\EntityType', [
'class' => 'AppBundle:Event',
'property' => 'title',
'query_builder' => function(EntityRepository $er) {
return $er->getEventQueryBuilder();
}
]));
// ...
public function getEventQueryBuilder()
{
if ( ... some condition ... ) {
return null;
}
$qb = $this->getEntityManager()->createQueryBuilder();
return $qb->select(...)->...;
}
|
Foundation 5 form theme¶
Contributed by
Jean-Christophe Cuvelier
in #12587.
In Symfony 2.6 we introduced a form theme for applications which use the ubiquitous Bootstrap CSS framework. In Symfony 2.8 we expanded our CSS framework support by adding a new form theme for Foundation 5 CSS framework.
Use the form_themes
configuration option to apply this theme to all your forms:
1 2 3 4 | # app/config/config.yml
twig:
form_themes:
- 'foundation_5_layout.html.twig'
|
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
New in Symfony 2.8: Form improvements symfony.com/index.php/blog/new-in-symfony-2-8-form-improvements
Tweet thisComments
https://github.com/symfony/symfony/blob/2.8/UPGRADE-2.8.md#form
but this class doesn't exist in current release s2.8 or s3.0. shouldn't it be `Symfony\Bridge\Doctrine\Form\Type\EntityType` ?
$builder->add('field', FooType::class) is as easy as $builder->add('field', 'foo').
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Busaev Andrey said on Nov 27, 2015 at 09:41 #1