Merge pull request #50245 from seanpdoyle/field-id-field-name-docs
Action View Docs: `field_id` and `field_name` examples [ci skip]
This commit is contained in:
commit
6908a66c50
@ -1780,12 +1780,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])
|
||||
|
@ -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).
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user