Default handling of remote forms

So form_with has data-remote by default, which is nice, but there is no built-in way to handle them. I understand that people may want to do it in their own way, but re-rendering form if there were any errors and redirecting with turbolinks:visit on success seems a reasonable default to me.

3 Likes

I came here to write this exact same thing.

Just played with a rails 6 app this past weekend and form errors are really awkward with form_with right now. It took my productivity down a couple notches since you need to go pop open Turbolinks and do some digging to figure out what the intended path forward is by default. (Perhaps scaffold controllers/forms have a solution pre-baked, but wasn’t expecting that creating a controller/form from scratch would be so hard.)

This blog post (Form validations with HTML5 and modern Rails – Jorge Manrubia) did an excellent job summarizing my exact scenario and outlined a possible path forward - I believe the post was written by someone at Basecamp :slight_smile:

So now I’m using a gem to handle basic form submission - turbolinks_render but as of late 2019 the maintainer basically said, Turbolinks next and Stimulus next will somehow make this not a problem?

Hoping that those tools are able to alleviate this awkward issue.


As an aside, I’d like to mention another form related WTF for me is the naming for disabling ajax based submission. You disable the “remote” behavior via setting the option local:true. I wish it was named remote:false, since even when local:true is set, the form is still going to submit to the server after all (just via a regular page POST). I always first interpret local as somehow the form is going to do something locally and never talk to the server (maybe just me?).

1 Like

Sadly, the scaffolds punt on this by setting the form to local: true, which is a cheat in my mind.

Walter

1 Like

I think this is similar to the issue I posted earlier, DHH replied saying Turbolinks 6 coming late summer / fall should fix these cases

Indeed it seems like DHH is already on it, so we probably should wait for a public release, which will either close this issue, or make it easier to implement.

1 Like