Action View Docs: `field_id` and `field_name` examples [ci skip]

Several code samples for `field_id` and `field_name` cite the use of
[text_field_tag][]-style helper. That usage is incorrect. The helper
interface that `field_id` and `field_name` mimic is the
[text_field][]-style helper, without the `_tag` suffix.

[text_field_tag]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-text_field_tag
[text_field]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-text_field
This commit is contained in:
Sean Doyle 2023-12-02 09:04:12 -05:00
parent 67fb4414e5
commit 9de8f1a26a
2 changed files with 8 additions and 8 deletions

View File

@ -1780,12 +1780,12 @@ module ActionView
# #
# <%= form_for @post do |f| %> # <%= form_for @post do |f| %>
# <%= f.text_field :title, name: f.field_name(:title, :subtitle) %> # <%= f.text_field :title, name: f.field_name(:title, :subtitle) %>
# <%# => <input type="text" name="post[title][subtitle]"> # <%# => <input type="text" name="post[title][subtitle]"> %>
# <% end %> # <% end %>
# #
# <%= form_for @post do |f| %> # <%= form_for @post do |f| %>
# <%= f.text_field :tag, name: f.field_name(:tag, multiple: true) %> # <%= f.text_field :tag, name: f.field_name(:tag, multiple: true) %>
# <%# => <input type="text" name="post[tag][]"> # <%# => <input type="text" name="post[tag][]"> %>
# <% end %> # <% end %>
# #
def field_name(method, *methods, multiple: false, index: @options[:index]) def field_name(method, *methods, multiple: false, index: @options[:index])

View File

@ -91,11 +91,11 @@ module ActionView
# attribute name. # attribute name.
# #
# <%= label_tag :post, :title %> # <%= label_tag :post, :title %>
# <%= text_field_tag :post, :title, aria: { describedby: field_id(:post, :title, :error) } %> # <%= text_field :post, :title, aria: { describedby: field_id(:post, :title, :error) } %>
# <%= tag.span("is blank", id: field_id(:post, :title, :error) %> # <%= tag.span("is blank", id: field_id(:post, :title, :error) %>
# #
# In the example above, the <tt><input type="text"></tt> element built by # In the example above, the <tt><input type="text"></tt> element built by
# the call to <tt>text_field_tag</tt> declares an # the call to <tt>text_field</tt> declares an
# <tt>aria-describedby</tt> attribute referencing the <tt><span></tt> # <tt>aria-describedby</tt> attribute referencing the <tt><span></tt>
# element, sharing a common <tt>id</tt> root (<tt>post_title</tt>, in this # element, sharing a common <tt>id</tt> root (<tt>post_title</tt>, in this
# case). # case).
@ -123,11 +123,11 @@ module ActionView
# Return the value generated by the <tt>FormBuilder</tt> for the given # Return the value generated by the <tt>FormBuilder</tt> for the given
# attribute name. # attribute name.
# #
# <%= text_field_tag :post, :title, name: field_name(:post, :title, :subtitle) %> # <%= text_field :post, :title, name: field_name(:post, :title, :subtitle) %>
# <%# => <input type="text" name="post[title][subtitle]"> # <%# => <input type="text" name="post[title][subtitle]"> %>
# #
# <%= text_field_tag :post, :tag, name: field_name(:post, :tag, multiple: true) %> # <%= text_field :post, :tag, name: field_name(:post, :tag, multiple: true) %>
# <%# => <input type="text" name="post[tag][]"> # <%# => <input type="text" name="post[tag][]"> %>
# #
def field_name(object_name, method_name, *method_names, multiple: false, index: nil) def field_name(object_name, method_name, *method_names, multiple: false, index: nil)
names = method_names.map! { |name| "[#{name}]" }.join names = method_names.map! { |name| "[#{name}]" }.join