Skip to content

Commit

Permalink
Fix RailsAdmin widgets not activated after a validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Aug 26, 2022
1 parent f8219bf commit a604da5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions spec/integration/rails_admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/rails_admin/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit a604da5

Please sign in to comment.