diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-11-21 21:48:38 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2016-12-13 21:02:36 +0100 |
commit | a6d065e39f9285119d75a05ee46c659f8b3c0db8 (patch) | |
tree | 80239fbd5fe2ddd7dfeaec8c6fe7bf49383cbbdf /actionview/lib/action_view/helpers/tags | |
parent | 34a1c7e284e9d307f61070dfb30f0d6ab34c74d2 (diff) | |
download | rails-a6d065e39f9285119d75a05ee46c659f8b3c0db8.tar.gz rails-a6d065e39f9285119d75a05ee46c659f8b3c0db8.tar.bz2 rails-a6d065e39f9285119d75a05ee46c659f8b3c0db8.zip |
form_with/fields: Don't output ids by default
Continuing 67f81cc where we decided not to output ids
by default in the new form helpers.
Went with @dhh's suggestion of just requiring ids on
fields being labelled:
https://github.com/rails/rails/issues/25197#issuecomment-231797117
Seems okay enough.
Diffstat (limited to 'actionview/lib/action_view/helpers/tags')
-rw-r--r-- | actionview/lib/action_view/helpers/tags/base.rb | 14 | ||||
-rw-r--r-- | actionview/lib/action_view/helpers/tags/label.rb | 4 |
2 files changed, 15 insertions, 3 deletions
diff --git a/actionview/lib/action_view/helpers/tags/base.rb b/actionview/lib/action_view/helpers/tags/base.rb index cf8a6d6028..b8c446cbed 100644 --- a/actionview/lib/action_view/helpers/tags/base.rb +++ b/actionview/lib/action_view/helpers/tags/base.rb @@ -13,6 +13,7 @@ module ActionView @object_name.sub!(/\[\]$/, "") || @object_name.sub!(/\[\]\]$/, "]") @object = retrieve_object(options.delete(:object)) + @skip_default_ids = options.delete(:skip_default_ids) @options = options @auto_index = Regexp.last_match ? retrieve_autoindex(Regexp.last_match.pre_match) : nil end @@ -81,9 +82,12 @@ module ActionView def add_default_name_and_id(options) index = name_and_id_index(options) options["name"] = options.fetch("name") { tag_name(options["multiple"], index) } - options["id"] = options.fetch("id") { tag_id(index) } - if namespace = options.delete("namespace") - options["id"] = options["id"] ? "#{namespace}_#{options['id']}" : namespace + + unless skip_default_ids? + options["id"] = options.fetch("id") { tag_id(index) } + if namespace = options.delete("namespace") + options["id"] = options["id"] ? "#{namespace}_#{options['id']}" : namespace + end end end @@ -154,6 +158,10 @@ module ActionView def name_and_id_index(options) options.key?("index") ? options.delete("index") || "" : @auto_index end + + def skip_default_ids? + @skip_default_ids + end end end end diff --git a/actionview/lib/action_view/helpers/tags/label.rb b/actionview/lib/action_view/helpers/tags/label.rb index b31d5fda66..cab15ae201 100644 --- a/actionview/lib/action_view/helpers/tags/label.rb +++ b/actionview/lib/action_view/helpers/tags/label.rb @@ -73,6 +73,10 @@ module ActionView def render_component(builder) builder.translation end + + def skip_default_ids? + false # The id is used as the `for` attribute. + end end end end |