Skip to content

Commit

Permalink
Don't add the checkbox's name attribute to its label for boolean fields.
Browse files Browse the repository at this point in the history
... which was causing HTML validation errors.
  • Loading branch information
Steve Jorgensen committed Feb 16, 2012
1 parent a7307c5 commit fb8f8e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/formtastic/inputs/boolean_input.rb
Expand Up @@ -57,8 +57,9 @@ def label_html_options

input_html_options.merge(
prev.merge(
:id => nil,
:for => input_html_options[:id]
:id => nil,
:name => nil,
:for => input_html_options[:id]
)
)
end
Expand Down Expand Up @@ -101,4 +102,4 @@ def checked?

end
end
end
end
4 changes: 4 additions & 0 deletions spec/inputs/boolean_input_spec.rb
Expand Up @@ -29,6 +29,10 @@
output_buffer.should_not have_tag('form li label input[@type="hidden"]', :count => 1) # invalid HTML5
end

it 'should not add a "name" attribute to the label' do
output_buffer.should_not have_tag('form li label[@name]')
end

it 'should generate a checkbox input' do
output_buffer.should have_tag('form li label input')
output_buffer.should have_tag('form li label input#post_allow_comments')
Expand Down

0 comments on commit fb8f8e1

Please sign in to comment.