Ticket #4627: radio_button_label_option.patch
| File radio_button_label_option.patch, 4.2 kB (added by gregg@kellogg-assoc.com, 3 years ago) |
|---|
-
actionpack/lib/action_view/helpers/form_helper.rb
old new 214 214 # hash with +options+. 215 215 # Example (call, result). Imagine that @post.category returns "rails": 216 216 # radio_button("post", "category", "rails") 217 # radio_button("post", "category", "java" )217 # radio_button("post", "category", "java", :label => "Java") 218 218 # <input type="radio" id="post_category" name="post[category]" value="rails" checked="checked" /> 219 # <input type="radio" id="post_category" name="post[category]" value="java" />219 # <input type="radio" id="post_category" name="post[category]" value="java">Java</input> 220 220 # 221 221 def radio_button(object_name, method, tag_value, options = {}) 222 222 InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_radio_button_tag(tag_value, options) … … 265 265 "#{@object_name}_#{@auto_index}_#{@method_name}_#{pretty_tag_value}" : 266 266 "#{@object_name}_#{@method_name}_#{pretty_tag_value}" 267 267 add_default_name_and_id(options) 268 tag("input", options) 268 if options.has_key?("label") 269 content_tag("input", html_escape(options.delete("label")), options) 270 else 271 tag("input", options) 272 end 269 273 end 270 274 271 275 def to_text_area_tag(options = {}) -
actionpack/lib/action_view/helpers/form_tag_helper.rb
old new 109 109 end 110 110 111 111 # Creates a radio button. 112 # 113 # Options: 114 # * <tt>:label</tt> - A string specifying the content of the tag. 115 # # Outputs <input id="people" name="people" type="radio" value="david">david</input> 116 # <%= radio_button_tag "people", "david", false, "label" => "david" %> 112 117 def radio_button_tag(name, value, checked = false, options = {}) 113 118 html_options = { "type" => "radio", "name" => name, "id" => name, "value" => value }.update(options.stringify_keys) 114 119 html_options["checked"] = "checked" if checked 115 tag :input, html_options 120 if (options.has_key?(:label)) 121 content_tag :input, html_options.delete("label"), html_options 122 else 123 tag :input, html_options 124 end 116 125 end 117 126 118 127 # Creates a submit button with the text <tt>value</tt> as the caption. If options contains a pair with the key of "disable_with", -
actionpack/test/template/form_helper_test.rb
old new 121 121 ) 122 122 end 123 123 124 def test_radio_button_with_label 125 assert_dom_equal('<input id="post_title_goodbye_world" name="post[title]" type="radio" value="Goodbye World">Goodby World</input>', 126 radio_button("post", "title", "Goodbye World", :label => "Goodby World") 127 ) 128 end 129 124 130 def test_text_area 125 131 assert_dom_equal( 126 132 '<textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea>', -
actionpack/test/template/form_tag_helper_test.rb
old new 51 51 assert_dom_equal expected, actual 52 52 end 53 53 54 def test_radio_button_tag_with_label 55 actual = radio_button_tag "people", "david", false, :label => "david" 56 expected = %(<input id="people" name="people" type="radio" value="david">david</input>) 57 assert_dom_equal expected, actual 58 end 59 54 60 def test_select_tag 55 61 actual = select_tag "people", "<option>david</option>" 56 62 expected = %(<select id="people" name="people"><option>david</option></select>)