Skip to content

Commit d4318d8

Browse files
committed
feat(inputs): add SelectInput with wupport foor tags option
1 parent 386d4fa commit d4318d8

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class ActiveAdmin::Inputs::SelectInput < Formtastic::Inputs::SelectInput
2+
def input_html_options
3+
super.merge(data: { tags: @options[:tags].present? })
4+
end
5+
end

spec/features/inputs/select2_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,49 @@
2020
expect(page).not_to have_selector("select.default-select")
2121
expect(page).not_to have_selector("select.select2")
2222
end
23+
24+
context "with tags: true option" do
25+
let(:invoice) { create_invoice }
26+
let(:selection) { '#444' }
27+
28+
before do
29+
register_form(Invoice) do |f|
30+
f.input :number, as: :select, collection: ["#111", "#222", "#333"], tags: true
31+
end
32+
end
33+
34+
context 'when entering option not in collection' do
35+
before { visit edit_admin_invoice_path(invoice) }
36+
37+
it "adds new option", js: true do
38+
expect_select2_options_count_to_eq(4)
39+
fill_select2_input(selection)
40+
expect_select2_options_count_to_eq(5)
41+
end
42+
end
43+
end
44+
45+
context "with tags: false option" do
46+
let(:selection) { '#444' }
47+
48+
before do
49+
register_form(Invoice) do |f|
50+
f.input :number, as: :select, collection: ["#111", "#222", "#333"], tags: false
51+
end
52+
end
53+
54+
context 'when entering option not in collection' do
55+
let(:selection) { '#444' }
56+
57+
before { visit edit_admin_invoice_path(create_invoice) }
58+
59+
it "doesn't add new option", js: true do
60+
expect_select2_options_count_to_eq(4)
61+
fill_select2_input(selection)
62+
expect_select2_options_count_to_eq(4)
63+
end
64+
end
65+
end
2366
end
2467

2568
context "when default config is select 2 and select control has default-select class" do

0 commit comments

Comments
 (0)