I created a multipage form using CraueFormFlowBundle. With this form I can create a new entity object or edit an existing one.
I then added the setting
protected $allowDynamicStepNavigation = true;
to allow navigating back and forth through the form's pages, however when using the form to edit an existing object I want to be able to jump straight to any page in the form. This does not seem to work - the object data is loaded and I can press next repeatedly until I get to the desired page.
Is there a way to render the page navigation when editing using CraueFormFlowBundle ?
My template includes:
{% include 'CraueFormFlowBundle:FormFlow:stepList.html.twig' %}
to create the navigation. Here is the editAction:
public function editDriverAction($id) {
$em = $this->getDoctrine()->getManager();
$formData = $em->getRepository('NewgtDriverBundle:NewgtDriver')->find($id);
if (!$formData) {
throw $this->createNotFoundException('Unable to find Driver.');
}
//$formData = new NewgtDriver(); // Your form data class. Has to be an object, won't work properly with an array.
$flow = $this->get('newgtDriver.form.flow.createDriver'); // must match the flow's service id
$flow->bind($formData);
// form of the current step
$form = $flow->createForm();
if ($flow->isValid($form)) {
$flow->saveCurrentStepData($form);
if ($flow->nextStep()) {
// form for the next step
$form = $flow->createForm();
} else {
// flow finished
$em = $this->getDoctrine()->getManager();
$em->persist($formData);
$em->flush();
$flow->reset(); // remove step data from the session
return $this->redirect($this->generateUrl('driver')); // redirect when done
}
}
return $this->render('NewgtDriverBundle:Driver:new.html.twig', array(
'form' => $form->createView(),
'flow' => $flow,
));
}