What event could we receive after a rails-ujs form replacement?

Receiving an event after the form is replaced seems impossible. The element that has fired the event is no longer available and rails-ujs silently can’t do anything.

There are dozens of issues and questions and people facing the same problem. Many of the answers are very old and even include jquery-ujs which probably leads to further confusion.

Some examples below:

My questions is - what could we attach and listen to to get a notification about a form replacement? Is there such a thing? Should there be?

I’ve decided to use Stimulus for this. The connect() method of the controllers is good enough for this logic and it follows the MutationObserver - Web APIs | MDN API

1 Like