Skip to content

Commit a3ff4ac

Browse files
authored
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.
1 parent ddd7953 commit a3ff4ac

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/Turbo/README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,16 @@ automatically:
9797

9898
```php
9999
/**
100-
* @Route("/product/new")
100+
* @Route("/product/new", name="product_new")
101101
*/
102102
public function newProduct(Request $request): Response
103103
{
104104
return $this->handleForm(
105-
$this->createForm(ProductFormType::class),
105+
$this->createForm(ProductFormType::class, null,
106+
[
107+
'action' => $this->generateUrl('product_new'),
108+
]
109+
),
106110
$request,
107111
function (FormInterface $form) {
108112
// save...
@@ -176,6 +180,17 @@ $builder
176180
]
177181
]);
178182
```
183+
> **NOTE Turbo ^7.0.0-beta.5:**
184+
> 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:
185+
186+
```php
187+
return $this->redirectToRoute('school', ['rmd' => time()], Response::HTTP_SEE_OTHER);
188+
```
189+
and in the listing template:
190+
191+
```php
192+
<a data-turbo-action="replace" href="/school/new?rdm={{ rdm }}">Add Product</a>
193+
```
179194

180195
#### More Turbo Drive Info
181196

0 commit comments

Comments
 (0)