Changeset 3174
- Timestamp:
- 11/23/05 21:59:20 (3 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/form_options_helper.rb (modified) (3 diffs)
- trunk/actionpack/test/template/form_options_helper_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r3163 r3174 1 1 *SVN* 2 3 * Introduce :selected option to the select helper. Allows you to specify a selection other than the current value of object.method. Specify :selected => nil to leave all options unselected. #2991 [Jonathan Viney <jonathan@bluewire.net.nz>] 2 4 3 5 * Initialize @optional in routing code to avoid warnings about uninitialized access to an instance variable. [Nicholas Seckar] trunk/actionpack/lib/action_view/helpers/form_options_helper.rb
r3156 r3174 48 48 # could become: 49 49 # 50 # <select name="post[person_id ">50 # <select name="post[person_id]"> 51 51 # <option></option> 52 52 # <option value="1" selected="selected">David</option> … … 60 60 # This allows the user to submit a form page more than once with the expected results of creating multiple records. 61 61 # In addition, this allows a single partial to be used to generate form inputs for both edit and create forms. 62 # 63 # By default, post.person_id is the selected option. Specify :selected => value to use a different selection 64 # or :selected => nil to leave all options unselected. 62 65 def select(object, method, choices, options = {}, html_options = {}) 63 66 InstanceTag.new(object, method, self, nil, options.delete(:object)).to_select_tag(choices, options, html_options) … … 297 300 html_options = html_options.stringify_keys 298 301 add_default_name_and_id(html_options) 299 content_tag("select", add_options(options_for_select(choices, value), options, value), html_options) 302 selected_value = options.has_key?(:selected) ? options[:selected] : value 303 content_tag("select", add_options(options_for_select(choices, selected_value), options, value), html_options) 300 304 end 301 305 trunk/actionpack/test/template/form_options_helper_test.rb
r3003 r3174 284 284 ) 285 285 end 286 287 def test_select_with_selected_value 288 @post = Post.new 289 @post.category = "<mus>" 290 assert_dom_equal( 291 "<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\" selected=\"selected\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>", 292 select("post", "category", %w( abe <mus> hest ), :selected => 'abe') 293 ) 294 end 295 296 def test_select_with_selected_nil 297 @post = Post.new 298 @post.category = "<mus>" 299 assert_dom_equal( 300 "<select id=\"post_category\" name=\"post[category]\"><option value=\"abe\">abe</option>\n<option value=\"<mus>\"><mus></option>\n<option value=\"hest\">hest</option></select>", 301 select("post", "category", %w( abe <mus> hest ), :selected => nil) 302 ) 303 end 286 304 287 305 def test_collection_select