diff options
author | Jeff Dean <jeff@zilkey.com> | 2010-05-15 16:22:35 -0400 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-05-15 22:30:21 +0200 |
commit | 6617d0189377a2f820c8f948589bb2d4a91155af (patch) | |
tree | 59f0939efd97063f733a1d746d6217fa7d58abfa /actionpack/lib/action_view | |
parent | d6cbb27e7b260c970bf7d07dc0b0591ed82cee2a (diff) | |
download | rails-6617d0189377a2f820c8f948589bb2d4a91155af.tar.gz rails-6617d0189377a2f820c8f948589bb2d4a91155af.tar.bz2 rails-6617d0189377a2f820c8f948589bb2d4a91155af.zip |
Sending :id => nil to form helpers now properly omits the "id" html element [#4559 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 932e9e2f95..414a5d4cd9 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -859,7 +859,13 @@ module ActionView options = options.stringify_keys tag_value = options.delete("value") name_and_id = options.dup - name_and_id["id"] = name_and_id["for"] + + if name_and_id["for"] + name_and_id["id"] = name_and_id["for"] + else + name_and_id.delete("id") + end + add_default_name_and_id_for_value(tag_value, name_and_id) options.delete("index") options["for"] ||= name_and_id["id"] @@ -1027,7 +1033,7 @@ module ActionView pretty_tag_value = tag_value.to_s.gsub(/\s/, "_").gsub(/\W/, "").downcase specified_id = options["id"] add_default_name_and_id(options) - options["id"] += "_#{pretty_tag_value}" unless specified_id + options["id"] += "_#{pretty_tag_value}" if specified_id.blank? && options["id"].present? else add_default_name_and_id(options) end @@ -1036,14 +1042,14 @@ module ActionView def add_default_name_and_id(options) if options.has_key?("index") options["name"] ||= tag_name_with_index(options["index"]) - options["id"] ||= tag_id_with_index(options["index"]) + options["id"] = options.fetch("id", tag_id_with_index(options["index"])) options.delete("index") elsif defined?(@auto_index) options["name"] ||= tag_name_with_index(@auto_index) - options["id"] ||= tag_id_with_index(@auto_index) + options["id"] = options.fetch("id", tag_id_with_index(@auto_index)) else options["name"] ||= tag_name + (options.has_key?('multiple') ? '[]' : '') - options["id"] ||= tag_id + options["id"] = options.fetch("id", tag_id) end end |