Skip to content

Commit 13114e5

Browse files
committed
Follow-up for #3630
- Add a spec - Apply Prettier
1 parent b666c63 commit 13114e5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

spec/integration/fields/polymorphic_assosiation_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
expect(@comment.commentable).to eq @hardball
2828
end
2929

30+
it 'clears the selected id on type change', js: true do
31+
@players = ['Jackie Robinson', 'Rob Wooten'].map { |name| FactoryBot.create :player, name: name }
32+
visit new_path(model_name: 'comment')
33+
select 'Player', from: 'comment[commentable_type]'
34+
find('input.ra-filtering-select-input').set('Rob')
35+
page.execute_script("document.querySelector('input.ra-filtering-select-input').dispatchEvent(new KeyboardEvent('keydown'))")
36+
expect(page).to have_selector('ul.ui-autocomplete li.ui-menu-item a')
37+
page.execute_script %{[...document.querySelectorAll('ul.ui-autocomplete li.ui-menu-item')].find(e => e.innerText.includes("Jackie Robinson")).click()}
38+
select 'Team', from: 'comment[commentable_type]'
39+
expect(find('#comment_commentable_id', visible: false).value).to eq ''
40+
end
41+
3042
context 'when the associated model is declared in a two-level namespace' do
3143
it 'successfully saves the record', js: true do
3244
polymorphic_association_tests = ['Jackie Robinson', 'Rob Wooten'].map do |name|

src/rails_admin/widgets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ import I18n from "./i18n";
258258
"options"
259259
);
260260
object_select.data("options", selected_data);
261-
object_select.val('');
261+
object_select.val("");
262262
object_select.filteringSelect("destroy");
263263
object_select.filteringSelect(selected_data);
264264
});

0 commit comments

Comments
 (0)