Project

General

Profile

Actions

Defect #28447

open

fields_for produces a broken <label for=“”> value

Added by Phlip Plumlee over 6 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
UI
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

Description

Here's some code from the redmine_people plugin illustrating the problem:

<%= f.fields_for :information do |information| >
&lt;p&gt;<
= information.text_field :middlename, :label => l(:label_people_middlename) >&lt;/p&gt;
&lt;p&gt;<
= f.text_field :lastname, :required => true %>&lt;/p&gt;

Then one of the fields declares a label:

&lt;p&gt;<%= information.select :gender, Person.get_genders, :label => l(:label_people_gender)%>&lt;/p&gt;

That generates this HTML:

&lt;p&gt;&lt;label for="person[information_attributes]_gender"&gt;Gender&lt;/label&gt;
&lt;select name="person[information_attributes][gender]" id="person_information_attributes_gender"&gt;
&lt;option selected="selected" value="0"&gt;Male&lt;/option&gt;
&lt;option value="1"&gt;Female&lt;/option&gt;
&lt;/select&gt;&lt;/p&gt;

The <label for=""> value has [] in it instead of underscores _, so it does not match the target field's id="person_information_attributes_gender". Clicking on the label does not put the keyboard focus into that <select> field.

The bug comes from this statement in LabelledFormBuilder:

@template.content_tag("label", text.html_safe,
:class => (@object && @object.errors[field].present? ? "error" : nil),
:for => (@object_name.to_s + "_" + field.to_s))

The object_name has [] in it, so something should replace them with "_".

No data to display

Actions

Also available in: Atom PDF