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

form_with is not assigning id's to inputs #29450

Closed
tomrossi7 opened this issue Jun 14, 2017 · 4 comments
Closed

form_with is not assigning id's to inputs #29450

tomrossi7 opened this issue Jun 14, 2017 · 4 comments

Comments

@tomrossi7
Copy link
Contributor

@tomrossi7 tomrossi7 commented Jun 14, 2017

Steps to reproduce

<%= f.label :name %>
<%= f.text_field :name %>

Expected behavior

I would expect it to assign ids so the label functions correctly as it does with form_for
which produces the following output:

  <label for="model_name">Name</label>
  <input type="text" name="model[name]" id="model_name">

Actual behavior

form_with produces a label with an invalid for attribute since the id is missing from the input:

  <label for="model_name">Name</label>
  <input type="text" name="model[name]">

System configuration

Rails version:
5.1.1

Ruby version:
2.3.3

@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Jun 14, 2017

That is by design. form_with don't assign id's to inputs.

@morgoth
Copy link
Member

@morgoth morgoth commented Jun 14, 2017

@rafaelfranca but it still produces for attribute. The form doesn't look nice this way:

form.label :content
form.text_field :name, id: "object_class_name_content"

And it's impossible to turn on generating ids, because of hardcoded https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/form_helper.rb#L717

@kaspth Why was it designed this way?

@kaspth
Copy link
Member

@kaspth kaspth commented Jun 14, 2017

@morgoth See the first point here: #25197 😊

@tomrossi7
Copy link
Contributor Author

@tomrossi7 tomrossi7 commented Jun 14, 2017

If that is the behavior, shouldn't the for attribute be removed from the label as well as the id on the input?

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

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.