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

Formtastic removes namespace option from non-formtastic inputs #1347

Open
yjukaku opened this issue Nov 4, 2021 · 0 comments
Open

Formtastic removes namespace option from non-formtastic inputs #1347

yjukaku opened this issue Nov 4, 2021 · 0 comments

Comments

@yjukaku
Copy link

yjukaku commented Nov 4, 2021

Hello, thanks for your work on this gem.

We're running into an issue where our form's namespace is being set correctly only on fields that use formtastic's f.input method. An example is probably the best way to explain:

# plain Rails
= form_for @user, namespace: "abc" do |f|
  = f.text_field :name #=> <input name="user[name]" id="abc_user_name"/>

= semantic_form_for @user, namespace: "abc" do |f|
   # GOOD
  = f.input :name #=> <input name="user[name]" id="abc_user_name"/>
   # BAD. We lose the namespace, because formtastic deleted it.
  = f.text_field :name #=> <input name="user[name]" id="user_name">

I understand that formtastic's code for semantic_form_for is doing an custom_namespace = options.delete(:namespace), which removes the namespace when it delegates to form_for. I'm assuming this is so that the namespace is respected by formtastic and not duplicated by Rails.

I can't think of an easy way to prevent this issue, unless formtastic wraps every call to f.text_field/f.file_field, etc. So are there any workarounds?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant