Skip to content

Commit

Permalink
Merge pull request rails#50245 from seanpdoyle/field-id-field-name-docs
Browse files Browse the repository at this point in the history
Action View Docs: `field_id` and `field_name` examples [ci skip]
  • Loading branch information
p8 committed Dec 3, 2023
1 parent fe64393 commit e83b3ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions actionview/lib/action_view/helpers/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1779,12 +1779,12 @@ def field_id(method, *suffixes, namespace: @options[:namespace], index: @options
#
# <%= 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])
Expand Down
12 changes: 6 additions & 6 deletions actionview/lib/action_view/helpers/form_tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ def form_tag(url_for_options = {}, options = {}, &block)
# 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).
Expand Down Expand Up @@ -123,11 +123,11 @@ def field_id(object_name, method_name, *suffixes, index: nil, namespace: nil)
# 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
Expand Down

0 comments on commit e83b3ed

Please sign in to comment.