Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix name_when_new validation on multiselect with form scope name #169

Merged
merged 1 commit into from
May 21, 2024

Conversation

chloerei
Copy link
Contributor

Example form:

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

It will raise

Validation failed: Name when new must match the regular name ('bar', in this case) on multiselect comboboxes.

But name foo[bar] is correct. The comparison in the validation is the parameter name, which is not the name of the actual input.

@chloerei chloerei force-pushed the fix-multiselect-free-text branch from ad0f3bb to 80bc7c9 Compare May 21, 2024 05:29
Copy link
Owner

@josefarias josefarias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stellar work @chloerei thanks for catching and fixing this. 👏

@josefarias josefarias merged commit e7dd68b into josefarias:main May 21, 2024
2 checks passed
@chloerei chloerei deleted the fix-multiselect-free-text branch May 21, 2024 05:43
@@ -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."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized, would be good to use the hidden field name in the error message as well.

Would appreciate a separate PR if you have time. No worries if not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I will make separate PR.

@josefarias josefarias added the bug Something isn't working label May 31, 2024
@josefarias josefarias changed the title fix name_when_new on multiselect with form scope name Fix name_when_new on multiselect with form scope name May 31, 2024
@josefarias josefarias changed the title Fix name_when_new on multiselect with form scope name Fix name_when_new validation on multiselect with form scope name May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants