検索フォームに問題があります。私の選択には何も含まれていない可能性があります。 これは、空のときにデフォルトのメッセージを表示する理由です。Symfony 3 ChoiceType - 属性empty_dataが無視されました
私の 'empty_data'属性を設定すると、何も起こりません、常に私の空の選択。 私に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';
}
:
$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',
));
フォームや情報作業正しく、表示されていないだけで 'empty_data' 属性があります。
「placeholder」属性は機能しますが、それは私が望むものではありません。
アイデアはありますか?
ありがとうございます!
あなたのコードのない写真を、あなたのコードを投稿してください。 –
完了です、ごめんなさい –
'empty_data'は、フォームのフロントエンドでオプションが選択されていないときにsymfonyに返される値です。フォーム自体に表示されることはありません。 http://symfony.com/doc/current/reference/forms/types/choice.html#empty-data – naththedeveloper