How to use rails_admin.dom_ready? #3600
-
I cannot understand how to use that event, I mean, if I put this code in console.log("Ciao");
$(document).on('rails_admin.dom_ready', function () {
console.log("Rails Admin DOM ready")
}); The Ciao word appears in console, but the phrase "Rails Admin DOM ready" never, even if I change page, I though the first time wasn't got fired because it was already fired when the event handler was registered, but I expect that rails_admin.dom_ready gets fired every time a new page is loaded. What am I missing? which is the way of detecting page changes on rails admin javascript put into ui.js? Thank you very much. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Ended up on using turbo events to understand when a page visit has completed rendering and loading the page: let currentURL = window.location.href;
$(document).on('turbo:load', function (event) {
currentURL = event.originalEvent.detail.url;
console.log("Page loaded via turbo", currentURL);
}); I still cannot understand the use case for |
Beta Was this translation helpful? Give feedback.
-
This is unexpected. And I found that the cause is the custom event name RailsAdmin use. I consider this as a regression and will attempt to fix. For now you can work around this by using
|
Beta Was this translation helpful? Give feedback.
-
Thank you very much |
Beta Was this translation helpful? Give feedback.
This is unexpected. And I found that the cause is the custom event name RailsAdmin use.
Currently it's
rails_admin.dom_ready
(separated by a period), unlike others which uses a colon (e.g.turbo:load
for Turbo). AndjQuery interprets a period-separated name as a namespaced event. So jQuery's
on
will listen to events with the type ofrails_admin
and the namespacedom_ready
, not the event typerails_admin.dom_ready
. Hence$(document).on('rails_admin.dom_ready' ...)
doesn't get invoked.I consider this as a regression and will attempt to fix. For now you can work around this by using
addEventListener
instead of jQuery'son
.