@pjo336 I have the exact same issue as you described. Did you figure out a work around?
Ok, I got this to work, but I’m not using target="_top"
. I’m using a Stimulus controller and listening for the turbo:submit-end
event and then performing a Turbo.visit
on a successful form submission. Invalid form errors are handled by Turbo by returning a 422 response.
The code if anyone is interested:
import { Controller } from "stimulus"
import * as Turbo from "@hotwired/turbo"
export default class extends Controller {
connect() {
this.element.addEventListener('turbo:submit-end', function (event){
if (event.detail.success) {
Turbo.visit(window.location.href)
}
})
}
}
Then my turbo-frame
:
<turbo-frame id="contact-name-edit" data-controller="form"></turbo-frame>
For everyone in this thread using Devise, can you please give these two PRs a try:
-
Respond with 422 Unprocessable Entity for non-GET HTML/JS requests with errors by carlosantoniodasilva · Pull Request #223 · heartcombo/responders · GitHub (merged into
responders
but no new gem release yet) - Return 422 status when login fails by ghiculescu · Pull Request #5340 · heartcombo/devise · GitHub (PR still open)
If you test these, please also remove any changes you made to your devise config, failure app, etc. Combined, these should make Devise work out of the box with Turbo Drive and Turbo Native. Please leave feedback on either/both PRs if you have any issues or suggestions!
I’ve added
gem "devise", git: "https://github.com/ghiculescu/devise.git", branch: "error-code-422"
gem "responders", git: "https://github.com/heartcombo/responders.git"
removed TurboController, this line, and all the data: {turbo: false}
I had in overriden views.
Seems to work exactly how it should @ghiculescu!
But I still needed config.navigational_formats = ["*/*", :html, :turbo_stream]
in for sign in to show errors. And maybe other things, but here’s where I noticed the difference.
Thank you!
Thanks for testing @miharekar and good pickup! I missed that I’d changed that in my Devise config. Can you please have another look now?
@ghiculescu yup, looks like it’s working as it should now
These gem locations seem to work well for me. Hopefully we can see new versions of the gems up soon.
@ghiculescu Still waiting…
Haha yep. Production gemfile:
gem "devise", github: "ghiculescu/devise", branch: "error-code-422" # https://github.com/heartcombo/devise/pull/5340 not yet merged
gem "responders", github: "heartcombo/responders" # https://github.com/heartcombo/responders/pull/223 not yet released
does this issue has any progress ? devise is the de-facto solution for many rails apps; i guess it’d helped many people