Ticket #2991: select_not_selected_option.diff
| File select_not_selected_option.diff, 3.2 kB (added by jonathan@bluewire.net.nz, 3 years ago) |
|---|
-
actionpack/test/template/form_options_helper_test.rb
old new 283 283 select("post", "category", %w( abe <mus> hest), :prompt => true, :include_blank => true) 284 284 ) 285 285 end 286 287 def test_select_with_not_selected 288 @post = Post.new 289 @post.category = "<mus>" 290 assert_dom_equal( 291 "<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>", 292 select("post", "category", %w( abe <mus> hest ), :not_selected => true) 293 ) 294 end 286 295 287 296 def test_collection_select 288 297 @posts = [ -
actionpack/lib/action_view/helpers/form_options_helper.rb
old new 47 47 # 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> 53 53 # <option value="2">Sam</option> … … 59 59 # to the database. Instead, a second model object is created when the create request is received. 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 # The option :not_selected => true can be used if the current model value should not be selected by default. 62 64 def select(object, method, choices, options = {}, html_options = {}) 63 65 InstanceTag.new(object, method, self, nil, options.delete(:object)).to_select_tag(choices, options, html_options) 64 66 end … … 296 298 def to_select_tag(choices, options, html_options) 297 299 html_options = html_options.stringify_keys 298 300 add_default_name_and_id(html_options) 299 content_tag("select", add_options(options_for_select(choices, value), options, value), html_options)301 content_tag("select", add_options(options_for_select(choices, options[:not_selected] ? nil : value), options, value), html_options) 300 302 end 301 303 302 304 def to_collection_select_tag(collection, value_method, text_method, options, html_options) -
actionpack/CHANGELOG
old new 1 1 *SVN* 2 2 3 * Add :not_selected option to select() to not select current model value. [Jonathan Viney <jonathan@bluewire.net.nz>] 4 3 5 * Initialize @optional in routing code to avoid warnings about uninitialized access to an instance variable. [Nicholas Seckar] 4 6 5 7 * Make ActionController's render honor the :locals option when rendering a :file. #1665. [Emanuel Borsboom, Marcel Molina Jr.]