diff --git a/spec/integration/rails_admin_spec.rb b/spec/integration/rails_admin_spec.rb index d320a7c396..bb6ccc37f9 100644 --- a/spec/integration/rails_admin_spec.rb +++ b/spec/integration/rails_admin_spec.rb @@ -196,6 +196,14 @@ click_link 'Back to admin' is_expected.to have_content 'Details for Player' end + + it 'triggers rails_admin.dom_ready right after a validation error' do + visit edit_path(model_name: 'player', id: player.id) + fill_in 'player[name]', with: 'on steroids' + find_button('Save').trigger 'click' + is_expected.to have_content 'Player failed to be updated' + is_expected.to have_css '.filtering-select[data-input-for="player_team_id"]' + end end context 'with invalid model name' do diff --git a/src/rails_admin/ui.js b/src/rails_admin/ui.js index fe04418683..3fcb4030cd 100644 --- a/src/rails_admin/ui.js +++ b/src/rails_admin/ui.js @@ -79,12 +79,14 @@ import I18n from "./i18n"; } ); - document.addEventListener("turbo:load", function () { + function triggerDomReady() { I18n.init($("html").attr("lang"), $("#admin-js").data("i18nOptions")); const event = new CustomEvent("rails_admin.dom_ready"); document.dispatchEvent(event); - }); + } + $(document).ready(triggerDomReady); + document.addEventListener("turbo:render", triggerDomReady); document.addEventListener("rails_admin.dom_ready", function () { $(".nav.nav-pills li.active").removeClass("active");