Bonjour,

Excusez moi de vous déranger mais j'aimerais faire une listbox dynamique sur les formulaire de symfony

https://i.stack.imgur.com/eMKZd.png
https://i.stack.imgur.com/gnDCQ.png

l'idée serait d'obtenir

<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>

à la place de

<select>
<option value="4">4</option>
</select>

Controller

$form = $this->createForm(ReservationType::class, $booking, ['id_service' => $service]);

Repository

public function findOneById($service)
    {
        return $this->createQueryBuilder('t')
            ->andWhere('t.service = :service')
            ->setParameter('service', $service)
            ;
   }

Formulaire

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $id_service = $options['id_service'];
        $builder
            ->add('nbPlaces', EntityType::class, [
                'class' => Transport::class,
                'label' => 'Nombre de places',
                'attr' => [
                    'placeholder' => "Nombre de places",
                ],
                'query_builder' => function (TransportRepository $transportRepository) use ($id_service) {
                    $req = $transportRepository->findOneById($id_service);
                    return $req;

                },
                'choice_label' => 'nbPlaces',
                'choice_value' => 'nbPlaces'
            ]);
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => Reservation::class,
            'id_service' => null
        ]);
    }

Merci d'avance

Aucune réponse