Skip to content

Commit 14e042a

Browse files
authored
Fix broken Selectize on polymorphic select field (#2839)
When building the select field in the polymorphic form, we omitted to pass `nil` to the choices argument, which resulted in an erroneous argument order, and a {} was passed to it instead. This caused the selectize gem to fail applying the `.selectize` method under the hood. We introduced this in #2447. Passing `nil` will now restore its intended behavior and allow selectize to perform the dynamic seach in the select field again. To ensure we don't hit this problem again, we implement some feature tests which specifically trigger the Selectize functionality. Fixes #2821
1 parent b1689d0 commit 14e042a

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

app/views/fields/polymorphic/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This partial renders an input element for polymorphic relationships.
2222

2323
<div class="field-unit__field">
2424
<%= pf.hidden_field(:type, value: field.class.name) %>
25-
<%= pf.select(:value, {}, data: {controller: field.html_controller}) do %>
25+
<%= pf.select(:value, nil, {}, data: {controller: field.html_controller}) do %>
2626
<%= grouped_options_for_select(field.associated_resource_grouped_options, field.selected_global_id, prompt: true) %>
2727
<% end %>
2828
</div>

spec/features/edit_page_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,18 @@
104104
customer.reload
105105
expect(customer.territory).to eq(country)
106106
end
107+
108+
it "allows selecting a resource and submitting the form", :js do
109+
_blog_post = create(:blog_post, title: "How to Bake Bread")
110+
_blog_post2 = create(:blog_post, title: "How to Play Guitar")
111+
tag = create(:blog_tag)
112+
113+
visit edit_admin_blog_tag_path(tag)
114+
find(".selectize-input").click
115+
find(".selectize-input").fill_in(with: "Bake Bread")
116+
find(".option", text: "How to Bake Bread").click
117+
click_button "Update Tag"
118+
119+
expect(page).to have_content("How to Bake Bread")
120+
end
107121
end

spec/features/log_entries_form_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515
)
1616
end
1717

18+
it "allows to type in the select field to find a match and select it", :js do
19+
_customer = create(:customer, name: "Brucey")
20+
_customer2 = create(:customer, name: "Nacho")
21+
22+
visit new_admin_log_entry_path
23+
fill_in "Action", with: "create"
24+
find(".selectize-input").click
25+
find(".selectize-input").fill_in(with: "Brucey")
26+
find(".option", text: "Brucey").click
27+
click_on "Create Log entry"
28+
29+
expect(page).to have_content("Brucey")
30+
end
31+
1832
it "shows the selected logeable value" do
1933
customer = create(:customer)
2034
log_entry = create(:log_entry, logeable: customer)

spec/features/new_page_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require "rails_helper"
2+
3+
RSpec.describe "Admin creates a new tag", type: :feature, js: true do
4+
it "allows selecting a resource and submitting the form" do
5+
_blog_post = create(:blog_post, title: "How to Bake Bread")
6+
_blog_post2 = create(:blog_post, title: "How to Play Guitar")
7+
8+
visit "/admin/blog/tags/new"
9+
find(".selectize-input").click
10+
find(".selectize-input").fill_in(with: "Bake Bread")
11+
find(".option", text: "How to Bake Bread").click
12+
click_button "Create Tag"
13+
14+
expect(page).to have_content("How to Bake Bread")
15+
end
16+
end

0 commit comments

Comments
 (0)