Skip to content

Commit

Permalink
Tag helper should output an attribute with the value 'false' instead …
Browse files Browse the repository at this point in the history
…of omitting the attribute, if the associated option is false but not nil.
  • Loading branch information
FooBarWidget authored and NZKoz committed Nov 13, 2008
1 parent 4c09210 commit 4e9abdd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
10 changes: 6 additions & 4 deletions actionpack/lib/action_view/helpers/tag_helper.rb
Expand Up @@ -133,10 +133,12 @@ def tag_options(options, escape = true)
unless options.blank?
attrs = []
if escape
options.each do |key, value|
next unless value
value = BOOLEAN_ATTRIBUTES.include?(key) ? key : escape_once(value)
attrs << %(#{key}="#{value}")
options.each_pair do |key, value|
if BOOLEAN_ATTRIBUTES.include?(key)
attrs << %(#{key}="#{key}") if value
else
attrs << %(#{key}="#{escape_once(value)}") if !value.nil?
end
end
else
attrs = options.map { |key, value| %(#{key}="#{value}") }
Expand Down
2 changes: 1 addition & 1 deletion actionpack/test/template/form_tag_helper_test.rb
Expand Up @@ -235,7 +235,7 @@ def test_label_tag_id_sanitized
assert_match VALID_HTML_ID, label_elem['for']
end

def test_boolean_optios
def test_boolean_options
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")
assert_dom_equal %(<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil)
assert_dom_equal %(<select id="people" multiple="multiple" name="people[]"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => true)
Expand Down
4 changes: 4 additions & 0 deletions actionpack/test/template/tag_helper_test.rb
Expand Up @@ -19,6 +19,10 @@ def test_tag_options_rejects_nil_option
assert_equal "<p />", tag("p", :ignored => nil)
end

def test_tag_options_accepts_false_option
assert_equal "<p value=\"false\" />", tag("p", :value => false)
end

def test_tag_options_accepts_blank_option
assert_equal "<p included=\"\" />", tag("p", :included => '')
end
Expand Down

0 comments on commit 4e9abdd

Please sign in to comment.