diff options
author | Andrew Kaspick <andrew@redlinesoftware.com> | 2008-09-30 14:15:36 -0500 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-10-07 15:17:22 +0100 |
commit | dce6ade4cdc2833b53bd600ef10f9bce83c7102d (patch) | |
tree | 70774db6de17c2e5a4e82f7832b213288fab3d1a /actionpack/lib | |
parent | 51b986619d88f7ba98be7d271188785cbbb541a0 (diff) | |
download | rails-dce6ade4cdc2833b53bd600ef10f9bce83c7102d.tar.gz rails-dce6ade4cdc2833b53bd600ef10f9bce83c7102d.tar.bz2 rails-dce6ade4cdc2833b53bd600ef10f9bce83c7102d.zip |
Ensure select_tag#name attribute uses [] when :multiple is true. [#1146 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_tag_helper.rb | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 208bf91dd4..7492348c50 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -62,7 +62,7 @@ module ActionView # # <option>3</option><option>4</option></select> # # select_tag "colors", "<option>Red</option><option>Green</option><option>Blue</option>", :multiple => true - # # => <select id="colors" multiple="multiple" name="colors"><option>Red</option> + # # => <select id="colors" multiple="multiple" name="colors[]"><option>Red</option> # # <option>Green</option><option>Blue</option></select> # # select_tag "locations", "<option>Home</option><option selected="selected">Work</option><option>Out</option>" @@ -70,14 +70,15 @@ module ActionView # # <option>Out</option></select> # # select_tag "access", "<option>Read</option><option>Write</option>", :multiple => true, :class => 'form_input' - # # => <select class="form_input" id="access" multiple="multiple" name="access"><option>Read</option> + # # => <select class="form_input" id="access" multiple="multiple" name="access[]"><option>Read</option> # # <option>Write</option></select> # # select_tag "destination", "<option>NYC</option><option>Paris</option><option>Rome</option>", :disabled => true # # => <select disabled="disabled" id="destination" name="destination"><option>NYC</option> # # <option>Paris</option><option>Rome</option></select> def select_tag(name, option_tags = nil, options = {}) - content_tag :select, option_tags, { "name" => name, "id" => name }.update(options.stringify_keys) + html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name + content_tag :select, option_tags, { "name" => html_name, "id" => name }.update(options.stringify_keys) end # Creates a standard text field; use these text fields to input smaller chunks of text like a username |