Skip to content

Commit 5a592a9

Browse files
committed
feat(select-input): add field value to collection if tags true
1 parent d4318d8 commit 5a592a9

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

app/inputs/active_admin/inputs/select_input.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@ class ActiveAdmin::Inputs::SelectInput < Formtastic::Inputs::SelectInput
22
def input_html_options
33
super.merge(data: { tags: @options[:tags].present? })
44
end
5+
6+
def raw_collection
7+
field_value = object.send(method)
8+
9+
@options[:tags].present? && field_value.present? ? (super.to_a << field_value).uniq : super
10+
end
511
end

spec/features/inputs/select2_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@
4040
expect_select2_options_count_to_eq(5)
4141
end
4242
end
43+
44+
context 'when initial value is not in inputs collection' do
45+
before do
46+
invoice.update!(number: selection)
47+
visit edit_admin_invoice_path(invoice)
48+
end
49+
50+
it "includes initial value as option", js: true do
51+
expect_select2_options_count_to_eq(5)
52+
end
53+
end
4354
end
4455

4556
context "with tags: false option" do

0 commit comments

Comments
 (0)