piranha / twinspark-js

Declarative enhancement for HTML: simple, composable, lean.
https://twinspark.js.org/
MIT License
421 stars 20 forks source link

Best way to handler redirect after sumit form? #39

Closed vldmr-k closed 11 months ago

vldmr-k commented 11 months ago

Hi!

I want to use ts-swap="morph" and redirect after submit form, but it doesn't work well.

attribute ts-req-after don't triggired, bcs status 3xx is not true

I found solution, response <script>window.location.href = '...';</script>, but this method remove form, and customer see white block while page reloading.

How it doing better?

piranha commented 11 months ago

The problem here is that JS can't catch redirects (see who asked that question 🤣).

So while I'm thinking what would be the best way to improve TwinSpark to handle cases like that, you can return a validated form + a <script> to redirect the user inside that form. Feels a bit ugly, but I have no better ideas right now. :\

HTMx has HX-Location, so maybe that's what I need to add..

vldmr-k commented 11 months ago

Wow. I had no idea that W3C doesn't allow this. Thank you for your anser.

PS: You encountered this problem when I was still going to school :)