-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Step rendering with Hotwired/Turbo #405
Comments
If needed, here is a custom /**
* @method User getUser()
*/
abstract class AbstractController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
{
/**
* Renders a view and sets the appropriate status code when a flow is listed in parameters.
*/
protected function renderFlow(string $view, array $parameters = [], Response $response = null): Response
{
$response = $this->renderForm($view, $parameters, $response);
foreach ($parameters as $v) {
if (!$v instanceof FormFlowInterface) {
continue;
}
if (200 === $response->getStatusCode() && $v->getStepsDoneCount() >= 1) {
$response->setStatusCode(422);
}
}
return $response;
}
} |
Thanks @mpiot that solved the problem perfectly! |
Thanks a lot @akincer . $jobSeeker = new JobSeeker(); // My entity
// Get existing flow data from session if it exists
$this->flow->bind($jobSeeker);
$form = $this->flow->createForm();
if ($this->flow->isValid($form)) {
$this->flow->saveCurrentStepData($form);
if ($this->flow->nextStep()) {
$form = $this->flow->createForm();
} else {
$this->flow->reset(); // remove step data from the session
return $this->redirectToRoute('app_home'); // redirect when done
}
}
// Debugging: Check current step
$currentStep = $this->flow->getCurrentStepNumber();
$loggerInterface->debug("Current step: " . $currentStep);
return $this->render(
'upload_resume/index.html.twig',
[
'title' => $translatorInterface->trans('upload_resume', domain: 'base'),
'form' => $form->createView(),
'flow' => $this->flow,
],
new Response(status: 422) // I added this and know it works. I was stucked since three days.
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've already solved this but wanted to point out to anyone using Hotwired/Turbo that step rendering is broken unless you send a 422 status. You can do something like this:
`if ($this->flow->getStepCount() === $this->flow->getCurrentStepNumber() && $form->isSubmitted() && $form->isValid())
{
$statusCode = 200;
// The last step has been executed so redirect or whatever you want here
}
else
{
$statusCode = 422;
}
return $this->renderForm('your template', [
'form' => $form,
'flow' => $this->flow,
], new Response(null, $statusCode));`
The text was updated successfully, but these errors were encountered: