Skip to content

Commit

Permalink
fix name_when_new on multiselect with form scope name
Browse files Browse the repository at this point in the history
  • Loading branch information
chloerei committed May 21, 2024
1 parent d3f9799 commit ad0f3bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/presenters/hotwire_combobox/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def name_when_new
def name_when_new_on_multiselect_must_match_original_name
return unless multiselect? && name_when_new.present?

unless name_when_new.to_s == name
unless name_when_new.to_s == hidden_field_name
errors.add :name_when_new, :must_match_original_name,
message: "must match the regular name ('#{name}', in this case) on multiselect comboboxes."
end
Expand Down
11 changes: 11 additions & 0 deletions test/helpers/hotwire_combobox/helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,20 @@ class HotwireCombobox::HelperTest < ApplicationViewTestCase
combobox_tag :foo, multiselect_chip_src: "some_path", name_when_new: :bar
end

assert_raises ActiveModel::ValidationError do
form_with scope: :foo do |form|
form.combobox :bar, multiselect_chip_src: "some_path", name_when_new: "foo[baz]"
end
end

assert_nothing_raised do
combobox_tag :foo, multiselect_chip_src: "some_path", name_when_new: :foo
combobox_tag :foo, multiselect_chip_src: "some_path", free_text: true

form_with scope: :foo, url: "some_path" do |form|
form.combobox :bar, multiselect_chip_src: "some_path", name_when_new: "foo[bar]"
form.combobox :bar, multiselect_chip_src: "some_path", free_text: true
end
end
end

Expand Down

0 comments on commit ad0f3bb

Please sign in to comment.