mirror of https://github.com/rails/rails
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:
parent
67fb4414e5
commit
9de8f1a26a
|
@ -1780,12 +1780,12 @@ module ActionView
|
|||
#
|
||||
# <%= form_for @post do |f| %>
|
||||
# <%= 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 %>
|
||||
#
|
||||
# <%= form_for @post do |f| %>
|
||||
# <%= f.text_field :tag, name: f.field_name(:tag, multiple: true) %>
|
||||
# <%# => <input type="text" name="post[tag][]">
|
||||
# <%# => <input type="text" name="post[tag][]"> %>
|
||||
# <% end %>
|
||||
#
|
||||
def field_name(method, *methods, multiple: false, index: @options[:index])
|
||||
|
|
|
@ -91,11 +91,11 @@ module ActionView
|
|||
# attribute name.
|
||||
#
|
||||
# <%= 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) %>
|
||||
#
|
||||
# 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>
|
||||
# element, sharing a common <tt>id</tt> root (<tt>post_title</tt>, in this
|
||||
# case).
|
||||
|
@ -123,11 +123,11 @@ module ActionView
|
|||
# Return the value generated by the <tt>FormBuilder</tt> for the given
|
||||
# attribute name.
|
||||
#
|
||||
# <%= text_field_tag :post, :title, name: field_name(:post, :title, :subtitle) %>
|
||||
# <%# => <input type="text" name="post[title][subtitle]">
|
||||
# <%= text_field :post, :title, name: field_name(:post, :title, :subtitle) %>
|
||||
# <%# => <input type="text" name="post[title][subtitle]"> %>
|
||||
#
|
||||
# <%= text_field_tag :post, :tag, name: field_name(:post, :tag, multiple: true) %>
|
||||
# <%# => <input type="text" name="post[tag][]">
|
||||
# <%= text_field :post, :tag, name: field_name(:post, :tag, multiple: true) %>
|
||||
# <%# => <input type="text" name="post[tag][]"> %>
|
||||
#
|
||||
def field_name(object_name, method_name, *method_names, multiple: false, index: nil)
|
||||
names = method_names.map! { |name| "[#{name}]" }.join
|
||||
|
|
Loading…
Reference in New Issue