Skip to content
This repository
Browse code

Register 'checked' as an HTML boolean attribute.

This way, 'tag :foo, :type => "checkbox", :checked => false' would output
the expected

  <input type="checkbox" />

instead of the old

  <input type="checkbox" checked="false" />

The latter would result in a checkbox that's initially checked.

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit 337c361e26fe5647036f94556fe792535a921f93 1 parent 19e9a1f
Hongli Lai authored November 18, 2008 jeremy committed November 18, 2008
2  actionpack/lib/action_view/helpers/tag_helper.rb
@@ -9,7 +9,7 @@ module Helpers #:nodoc:
9 9
     module TagHelper
10 10
       include ERB::Util
11 11
 
12  
-      BOOLEAN_ATTRIBUTES = %w(disabled readonly multiple).to_set
  12
+      BOOLEAN_ATTRIBUTES = %w(disabled readonly multiple checked).to_set
13 13
       BOOLEAN_ATTRIBUTES.merge(BOOLEAN_ATTRIBUTES.map(&:to_sym))
14 14
 
15 15
       # Returns an empty HTML tag of type +name+ which by default is XHTML
1  actionpack/test/template/form_tag_helper_test.rb
@@ -238,6 +238,7 @@ def test_label_tag_id_sanitized
238 238
   def test_boolean_options
239 239
     assert_dom_equal %(<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes")
240 240
     assert_dom_equal %(<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil)
  241
+    assert_dom_equal %(<input type="checkbox" />), tag(:input, :type => "checkbox", :checked => false)
241 242
     assert_dom_equal %(<select id="people" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => true)
242 243
     assert_dom_equal %(<select id="people_" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people[]", "<option>david</option>", :multiple => true)
243 244
     assert_dom_equal %(<select id="people" name="people"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => nil)

0 notes on commit 337c361

Please sign in to comment.
Something went wrong with that request. Please try again.