I have a problem with my search form. It is possible that my select contains nothing. This is why I would like to display a default message when it is empty.
However when I set my 'empty_data' attribute, nothing happens, always my empty select. My FormType :
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('organisation',ChoiceType::class,array(
'choices' => $options['distributeurs'],
'choice_label' => function ($value, $key, $index) {
return $value->getOrganisation();
},
'choice_value' => 'id',
'empty_data' => 'No distributor found'
));
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'distributeurs' => 'ProjectBundle\Entity\Organisation\Organisation',
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'projectbundle_organisation_search';
}
And at the level of the controller :
$distributeurs = $em->getRepository('ProjectBundle:Organisation\Organisation')->createQueryBuilder('a')
->where('a.id IN (:distributeurs)')->setParameter('distributeurs',$organisationDistriId)->getQuery()->execute();
$form = $this->createForm('ProjectBundle\Form\Organisation\OrganisationDistributeurType', null, array(
'distributeurs' => $distributeurs,
'action' => $this->generateUrl('admin_organisations_index'),
'method' => 'GET',
));
The form and information work correctly, there is just the 'empty_data' attribute that is not displayed.
The 'placeholder' attribute works but that's not what I want.
Do you have an idea ?
Thanks !