From a3ff4acc1c604040a51df4baf88c7d9d2b293ab3 Mon Sep 17 00:00:00 2001 From: Pierre Joye Date: Wed, 16 Jun 2021 16:06:56 +0700 Subject: [PATCH 1/2] Update Form example Without specifying the action, Turbo redirect the full page to /. name="product_new" is not necessary in this specific example, it however may help newcomer to understand they can have separate route for this action (even if not recommended by the Symfony Form docs). Not sure if it is a bug in turbo or me doing wrong, adding this fixes it. --- src/Turbo/README.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Turbo/README.md b/src/Turbo/README.md index 0c0d91bea21..6e468f648ec 100644 --- a/src/Turbo/README.md +++ b/src/Turbo/README.md @@ -97,12 +97,16 @@ automatically: ```php /** - * @Route("/product/new") + * @Route("/product/new", name="product_new") */ public function newProduct(Request $request): Response { return $this->handleForm( - $this->createForm(ProductFormType::class), + $this->createForm(ProductFormType::class, null, + [ + 'action' => $this->generateUrl('product_new'), + ] + ), $request, function (FormInterface $form) { // save... @@ -176,6 +180,17 @@ $builder ] ]); ``` +> **NOTE Turbo ^7.0.0-beta.5:** +> If Turbo ^7.0.0-beta.5 or lower (may be still valid with future version), there is a bug with turbo-frame and form submit. F.e., a link to add a product will work the 1st time, the frame will have the new product form, on submit, the frame will be updated using the products listing. At this point the new link won't work anymore. This is cache issue in Turbo. To avoid it add a ramdom value as get parameter, microtime(true) will make it unique for one client: + +```php +return $this->redirectToRoute('school', ['rmd' => time()], Response::HTTP_SEE_OTHER); +``` +and in the listing template: + +```php +Add Product +``` #### More Turbo Drive Info From 3248ee01daf8f8be0253c71d759ead0c008e3748 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Tue, 22 Jun 2021 16:05:07 -0400 Subject: [PATCH 2/2] Removing warning not needed anymore and minor cs --- src/Turbo/README.md | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/Turbo/README.md b/src/Turbo/README.md index 6e468f648ec..2771340fd4b 100644 --- a/src/Turbo/README.md +++ b/src/Turbo/README.md @@ -102,11 +102,9 @@ automatically: public function newProduct(Request $request): Response { return $this->handleForm( - $this->createForm(ProductFormType::class, null, - [ + $this->createForm(ProductFormType::class, null, [ 'action' => $this->generateUrl('product_new'), - ] - ), + ]), $request, function (FormInterface $form) { // save... @@ -180,17 +178,6 @@ $builder ] ]); ``` -> **NOTE Turbo ^7.0.0-beta.5:** -> If Turbo ^7.0.0-beta.5 or lower (may be still valid with future version), there is a bug with turbo-frame and form submit. F.e., a link to add a product will work the 1st time, the frame will have the new product form, on submit, the frame will be updated using the products listing. At this point the new link won't work anymore. This is cache issue in Turbo. To avoid it add a ramdom value as get parameter, microtime(true) will make it unique for one client: - -```php -return $this->redirectToRoute('school', ['rmd' => time()], Response::HTTP_SEE_OTHER); -``` -and in the listing template: - -```php -Add Product -``` #### More Turbo Drive Info