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?

https://github.com/rails/jquery-ujs/issues/223

https://github.com/rails/rails/issues/30692 https://github.com/rails/rails/issues/32438

2 Likes

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