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

Comments

Projects
None yet
4 participants
@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

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Jun 14, 2017

Member

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

Member

rafaelfranca commented Jun 14, 2017

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

@morgoth

This comment has been minimized.

Show comment
Hide comment
@morgoth

morgoth Jun 14, 2017

Member

@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?

Member

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

This comment has been minimized.

Show comment
Hide comment
@kaspth

kaspth Jun 14, 2017

Member

@morgoth See the first point here: #25197 😊

Member

kaspth commented Jun 14, 2017

@morgoth See the first point here: #25197 😊

@tomrossi7

This comment has been minimized.

Show comment
Hide comment
@tomrossi7

tomrossi7 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?

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