Hotwire Discussion

Turbo:load after Form Error

Hi,

I’m using:

ruby '3.0.2'
hotwire-rails (0.1.3)
rails (6.1.4.1)

I have a form, when it’s produce an validation error it used this method:
render :edit, status: :unprocessable_entity

After this the turbo:load event is not fired. After a successfully submitted form it’s fired.

I tried also turbo:frame-load but that looks also wrong for me.

What should i use?

Best regards,
Sebastian

You could force the load event to be fired after a failed form submission with something like this:

document.addEventListener("turbo:submit-end", (event) => {
  if(!event.detail.success) {
    document.dispatchEvent(new Event('turbo:load'))
  }
})