Skip to content

Commit 1550260

Browse files
committed
Do not pick up the placeholder as selection in filtering-multiselect. Fixes #2807
1 parent 9e528f1 commit 1550260

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

app/assets/javascripts/rails_admin/ra.filtering-multiselect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118

119119
/* Add all to selection */
120120
this.addAll.click(function(e){
121-
widget._select($('option', widget.collection));
121+
widget._select($('option:not(:disabled)', widget.collection));
122122
e.preventDefault();
123123
widget.selection.trigger('change');
124124
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
require 'spec_helper'
2+
3+
describe 'FilteringMultiSelect widget', type: :request, js: true do
4+
subject { page }
5+
6+
describe 'Choose all button' do
7+
let(:team) { FactoryBot.create :team }
8+
let!(:players) { FactoryBot.create_list :player, 2 }
9+
before do
10+
RailsAdmin.config Team do
11+
field :players
12+
end
13+
end
14+
15+
it 'picks all available items' do
16+
visit edit_path(model_name: 'team', id: team.id)
17+
click_link 'Choose all'
18+
expect(all(:css, '#team_player_ids option', visible: false).map(&:value)).to match_array players.map(&:id).map(&:to_s)
19+
end
20+
21+
context 'when associated_collection_cache_all is false' do
22+
before do
23+
RailsAdmin.config Team do
24+
field(:players) { associated_collection_cache_all false }
25+
end
26+
end
27+
28+
it "does not pick the placeholder for selection" do
29+
visit edit_path(model_name: 'team', id: team.id)
30+
click_link 'Choose all'
31+
expect(page).not_to have_css('#team_player_ids option', visible: false)
32+
expect(page).not_to have_css('.ra-multiselect-selection option')
33+
end
34+
35+
it 'picks all available items' do
36+
visit edit_path(model_name: 'team', id: team.id)
37+
find('input.ra-multiselect-search').set('P')
38+
page.execute_script("$('input.ra-multiselect-search').trigger('focus')")
39+
page.execute_script("$('input.ra-multiselect-search').trigger('keydown')")
40+
expect(page).to have_css('.ra-multiselect-collection option', text: /Player/)
41+
click_link 'Choose all'
42+
expect(all(:css, '#team_player_ids option', visible: false).map(&:value)).to match_array players.map(&:id).map(&:to_s)
43+
end
44+
end
45+
end
46+
end

0 commit comments

Comments
 (0)