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

Duplicate ID #1192

Closed
dcalixto opened this issue Mar 18, 2016 · 13 comments · May be fixed by #1212
Closed

Duplicate ID #1192

dcalixto opened this issue Mar 18, 2016 · 13 comments · May be fixed by #1212
Labels

Comments

@dcalixto
Copy link

On a user edit page i have several forms using formstatic but formstatic is duplicating the ids, i would like to know if have a way to change this issue. here a exemple:

<form accept-charset="UTF-8" action="/users/test" class="formtastic user" id="edit_user_1" method="post" novalidate="novalidate">

the edit_user_1 is duplicating on the others forms.

thank's

@mikz
Copy link
Contributor

mikz commented Mar 18, 2016

See the "Namespaced forms all multiple Formtastic forms to exist on the one page without DOM id clashes and invalid HTML documents." in the documentation of semantic_form_for.

That should solve your problem.

@dcalixto
Copy link
Author

@mikz thank's for your reply, i placed the namespace and did not solve.

@mikz
Copy link
Contributor

mikz commented Mar 18, 2016

@dcalixto you can still pass :html option to it. So something like this would solve your problem:

semantic_form_for(@user, html: { id: 'prefixed_form' })

@dcalixto
Copy link
Author

thank you very much @mikz , and unintentionally abuse, the same probem seems to appear on submit:

i've tried the same logic but seems not solve.

Duplicate ID "user_submit_action"

  <%= form.actions do %>
        <%= form.action(:submit, :label => "Save",  :button_html => { :class => "btn", id: 'button_address'}) %>
        <% end %>

@mikz
Copy link
Contributor

mikz commented Mar 21, 2016

@dcalixto could you post the generated html ? It is weird, that button_html would not work.

@justinfrench justinfrench added this to the 4.0 beta milestone Mar 26, 2016
@mikz
Copy link
Contributor

mikz commented Mar 29, 2016

@dcalixto I check the source and the tests and I don't see any possibility why :namespace option should not work. Could you paste an example how you were trying to use it?

It would help us a lot. To improve documentation, we need to learn how people use it and what mistakes they make.

@fredngo
Copy link

fredngo commented Apr 14, 2016

I too am experiencing the same problem with the namespace option. The versions used are: formtastic (3.1.4) and formtastic-bootstrap (3.1.1). (I wonder if it's a formtastic-bootstrap problem.)

Using the plain old Rails form builder:

= form_for(@animal, namespace: 'cat', url: zookeeper_animal_path) do |f|

gets me:

<form id="cat_edit_zoo_animal_249" class="edit_zoo_animal" method="post" accept-charset="UTF-8" action="/zookeeper/animals/249">

whereas using Formtastic:

= semantic_form_for(@animal, namespace: 'cat', url: zookeeper_animal_path) do |f|

gets me:

<form id="edit_zoo_animal_249" class="formtastic zoo_animal" method="post" accept-charset="UTF-8" action="/zookeeper/animals/249" novalidate="novalidate">

So the cat namespace is missing in the id.

Note that in this example, the ActiveRecord model is class Zoo::Animal but the controller I am posting to is class Zookeeper::Animal so there is some Ruby namespacing going on.

mikz added a commit to mikz/formtastic that referenced this issue Apr 14, 2016
@mikz
Copy link
Contributor

mikz commented Apr 14, 2016

@fredngo Thanks for the report! I made a PR (#1212) with a regression test to verify it surely fails. And it does.

I'm not sure why, how to fix it or how much time I'll have to work on that. If you feel like, feel free to chip in.

@fredngo
Copy link

fredngo commented Apr 14, 2016

Wow, thanks for the quick response @mikz ! For now that the issue is documented at least.

@mateusg
Copy link

mateusg commented Jul 11, 2018

I'm experiencing the same problem with duplicate ids on the submit buttons and forms.

I think this is happening because the :namespace option isn't being passed to the original implementation of form_for. It gets remapped as custom_namespace.

@mikz Do you know if there's a reason it was remapped like this?

@mikz
Copy link
Contributor

mikz commented Jul 12, 2018

I made #1065 to fix #904. It was doing nasty stuff and changing class variables when rendering forms.

It is possible I did not fully understand the implications and it has a bug that prevents using the :namespace option. We should verify the regression test #1212 failed/passed before these changes. If so then it indeed broke it.

@justinfrench justinfrench removed this from the 4.0 beta milestone Jun 21, 2020
@fredngo
Copy link

fredngo commented Jul 27, 2020

@justinfrench #1212 doesn't seem to be merged yet; did some other fix solve this bug?

@justinfrench
Copy link
Member

@fredngo I closed this as part of a mass clean-up. If you have the time to pull all this together in one PR, I'd really appreciate the help, as I don't have the time to maintain this like I used to.

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

Successfully merging a pull request may close this issue.

5 participants