Closed matthieumastadenis closed 1 month ago
Turbo does require a redirect for form responses.. you can add the :prevent
modifier to your action to let Stimulus/LiveComponent handle the submission (instead of Turbo)
Turbo does require a redirect for form responses.. you can add the
:prevent
modifier to your action to let Stimulus/LiveComponent handle the submission (instead of Turbo)
Thanks, it works :+1:
Hello again,
Following my previous issue #2048, I have another one that's directly related to the same code.
I work with a live component containing two things : a table of users and a search form allowing to filter the users displayed in the table.
When I simply type into the form fields, my component is correctly refreshed, and after I solved my previous issue everything is fine (meaning the table correctly re-renders with a new list of users corresponding to my search).
But when I try to use the submit button, I get a JS error :
Error: Form responses must redirect to another location
.I actually already encountered this error previously, when I tried the same things but with a regular symfony controller instead of a live component. Since my form is a search form meant to refine results on the same page, performing a redirect is not the correct solution here. So I ended up returning a 202 HTTP status code instead of 200 when my form was submitted. Despite this being an ugly fix rather than an elegant solution, it worked.
But now I'm not in a regular controller. I'm trying to implement the same thing in a Live Component instead. And so I don't know how to solve my JS error because:
As a last resort I know I could just remove the submit button, because everything works fine by just typing into the form fields, without clicking on that button. But I still wonder how to make this work properly with the button? Did I do something wrong?
Thanks,