Hotwire Discussion

Form submissions with invalid responses and Turbo Native

Hey, folks. I’ve been working on the Turbo Laravel package and I got a question for y’all. Currently, there seems to be two valid ways to handle invalid form submissions:

  1. Flash the errors and redirect to the form page, which will render the form with errors
  2. Render a non-200 response with the invalid form (usually a 422 status code).

We’re are currently doing the first approach in Laravel, but I’ve seen some Rails tutorials/videos using the second. At first, I thought it was a matter of preference, which is fine. However, after playing with Turbo Native for a bit, I found out the second approach works best there. Keep in mind that I’m new to the mobile world, so take this with a grain of salt. It seems like Turbo Native handles the first approach like a regular visit, closing the modal only to re-open it again with invalid messages. While the latter approach simply replaces the form without interacting with the modal or any navigation at all.

I’ve shared more details, including videos for the Turbo Native behavior, in this issue on the Turbo Laravel repository.

I wanted to confirm this is the expected behavior for the Turbo Native side of handling invalid form submissions and if so, the second approach is the “best one” then.

Cheers,

1 Like