craue / CraueFormFlowBundle

Multi-step forms for your Symfony project.
MIT License
736 stars 118 forks source link

EntityType multiple don't save data #351

Closed vl20100 closed 4 years ago

vl20100 commented 4 years ago

Hi,

I'm a begginer with the FormFlowBundle. I have a flow with 2 steps. On first step, I have just an EntityType multiple.

    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
            ->add("interventions", EntityType::class, [
                "label" => false,
                "class" => Intervention::class,
                "query_builder" => function(EntityRepository $er) {
                    $qb = $er->createQueryBuilder('i');
                    $qb->where($qb->expr()->isNotNull('i.ordre'));
                    $qb->orderBy("i.ordre", "ASC");
                    return $qb;
                },
                "choice_label" => "nom",
                "multiple" => true,
                "expanded" => true
            ])
        ;

    }

When I come on the second step, my form model has not the previous field set.

image

Here is my action in controller :

    public function indexRdvAction(Request $request, $idMarque)
    {
        $em = $this->getDoctrine()->getManager();

        //formflow
        $formData = new Rdv();
        $flow = $this->get("appBundle.admin.form.flow.rdv");
        $flow->bind($formData);
        $form = $flow->createForm();

        if($flow->isValid($form))
        {

            $flow->saveCurrentStepData($form);

            if($flow->nextStep())
            {
                $form = $flow->createForm();
            }
            else
            {
                // flow finished
                $formData->setDateCreation(new \DateTime());

                $em->persist($formData);
                $em->flush();

                $flow->reset(); // Remove data from the session

                return $this->redirectToRoute("validation");
            }
        }

        $templateName = "formflow_step" . $flow->getCurrentStepNumber() . "_" . $flow->getCurrentStepLabel() . ".html.twig";

        return $this->render("default/formflow/" . $templateName, [
            "form" => $form->createView(),
            "flow" => $flow,
            "rdv" => $formData
        ]);
    }

When I dump my request, I can see my selected entities :

image

Is there a bug or did I do a mistake ?

Thank you.

vl20100 commented 4 years ago

The problem came from my template and customized form field.