mirror of https://github.com/rails/rails
docs, cleanup mixed indents within `form_options_helper.rb` RDoc.
[ci skip] This fixes the broken code block rendering and indents the examples within the parameter list.
This commit is contained in:
parent
c5fc7b5564
commit
aade0a0412
|
@ -14,81 +14,81 @@ module ActionView
|
||||||
#
|
#
|
||||||
# * <tt>:include_blank</tt> - set to true or a prompt string if the first option element of the select element is a blank. Useful if there is not a default value required for the select element.
|
# * <tt>:include_blank</tt> - set to true or a prompt string if the first option element of the select element is a blank. Useful if there is not a default value required for the select element.
|
||||||
#
|
#
|
||||||
# select("post", "category", Post::CATEGORIES, {include_blank: true})
|
# select("post", "category", Post::CATEGORIES, {include_blank: true})
|
||||||
#
|
#
|
||||||
# could become:
|
# could become:
|
||||||
#
|
#
|
||||||
# <select name="post[category]">
|
# <select name="post[category]">
|
||||||
# <option></option>
|
# <option></option>
|
||||||
# <option>joke</option>
|
# <option>joke</option>
|
||||||
# <option>poem</option>
|
# <option>poem</option>
|
||||||
# </select>
|
# </select>
|
||||||
#
|
#
|
||||||
# Another common case is a select tag for a <tt>belongs_to</tt>-associated object.
|
# Another common case is a select tag for a <tt>belongs_to</tt>-associated object.
|
||||||
#
|
#
|
||||||
# Example with @post.person_id => 2:
|
# Example with <tt>@post.person_id => 2</tt>:
|
||||||
#
|
#
|
||||||
# select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, {include_blank: 'None'})
|
# select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, {include_blank: 'None'})
|
||||||
#
|
#
|
||||||
# could become:
|
# could become:
|
||||||
#
|
#
|
||||||
# <select name="post[person_id]">
|
# <select name="post[person_id]">
|
||||||
# <option value="">None</option>
|
# <option value="">None</option>
|
||||||
# <option value="1">David</option>
|
# <option value="1">David</option>
|
||||||
# <option value="2" selected="selected">Sam</option>
|
# <option value="2" selected="selected">Sam</option>
|
||||||
# <option value="3">Tobias</option>
|
# <option value="3">Tobias</option>
|
||||||
# </select>
|
# </select>
|
||||||
#
|
#
|
||||||
# * <tt>:prompt</tt> - set to true or a prompt string. When the select element doesn't have a value yet, this prepends an option with a generic prompt -- "Please select" -- or the given prompt string.
|
# * <tt>:prompt</tt> - set to true or a prompt string. When the select element doesn't have a value yet, this prepends an option with a generic prompt -- "Please select" -- or the given prompt string.
|
||||||
#
|
#
|
||||||
# select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, {prompt: 'Select Person'})
|
# select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, {prompt: 'Select Person'})
|
||||||
#
|
#
|
||||||
# could become:
|
# could become:
|
||||||
#
|
#
|
||||||
# <select name="post[person_id]">
|
# <select name="post[person_id]">
|
||||||
# <option value="">Select Person</option>
|
# <option value="">Select Person</option>
|
||||||
# <option value="1">David</option>
|
# <option value="1">David</option>
|
||||||
# <option value="2">Sam</option>
|
# <option value="2">Sam</option>
|
||||||
# <option value="3">Tobias</option>
|
# <option value="3">Tobias</option>
|
||||||
# </select>
|
# </select>
|
||||||
#
|
#
|
||||||
# Like the other form helpers, +select+ can accept an <tt>:index</tt> option to manually set the ID used in the resulting output. Unlike other helpers, +select+ expects this
|
# * <tt>:index</tt> - like the other form helpers, +select+ can accept an <tt>:index</tt> option to manually set the ID used in the resulting output. Unlike other helpers, +select+ expects this
|
||||||
# option to be in the +html_options+ parameter.
|
# option to be in the +html_options+ parameter.
|
||||||
#
|
#
|
||||||
# select("album[]", "genre", %w[rap rock country], {}, { index: nil })
|
# select("album[]", "genre", %w[rap rock country], {}, { index: nil })
|
||||||
#
|
#
|
||||||
# becomes:
|
# becomes:
|
||||||
#
|
#
|
||||||
# <select name="album[][genre]" id="album__genre">
|
# <select name="album[][genre]" id="album__genre">
|
||||||
# <option value="rap">rap</option>
|
# <option value="rap">rap</option>
|
||||||
# <option value="rock">rock</option>
|
# <option value="rock">rock</option>
|
||||||
# <option value="country">country</option>
|
# <option value="country">country</option>
|
||||||
# </select>
|
# </select>
|
||||||
#
|
#
|
||||||
# * <tt>:disabled</tt> - can be a single value or an array of values that will be disabled options in the final output.
|
# * <tt>:disabled</tt> - can be a single value or an array of values that will be disabled options in the final output.
|
||||||
#
|
#
|
||||||
# select("post", "category", Post::CATEGORIES, {disabled: 'restricted'})
|
# select("post", "category", Post::CATEGORIES, {disabled: 'restricted'})
|
||||||
#
|
#
|
||||||
# could become:
|
# could become:
|
||||||
#
|
#
|
||||||
# <select name="post[category]">
|
# <select name="post[category]">
|
||||||
# <option></option>
|
# <option></option>
|
||||||
# <option>joke</option>
|
# <option>joke</option>
|
||||||
# <option>poem</option>
|
# <option>poem</option>
|
||||||
# <option disabled="disabled">restricted</option>
|
# <option disabled="disabled">restricted</option>
|
||||||
# </select>
|
# </select>
|
||||||
#
|
#
|
||||||
# When used with the <tt>collection_select</tt> helper, <tt>:disabled</tt> can also be a Proc that identifies those options that should be disabled.
|
# When used with the <tt>collection_select</tt> helper, <tt>:disabled</tt> can also be a Proc that identifies those options that should be disabled.
|
||||||
#
|
#
|
||||||
# collection_select(:post, :category_id, Category.all, :id, :name, {disabled: lambda{|category| category.archived? }})
|
# collection_select(:post, :category_id, Category.all, :id, :name, {disabled: lambda{|category| category.archived? }})
|
||||||
#
|
#
|
||||||
# If the categories "2008 stuff" and "Christmas" return true when the method <tt>archived?</tt> is called, this would return:
|
# If the categories "2008 stuff" and "Christmas" return true when the method <tt>archived?</tt> is called, this would return:
|
||||||
# <select name="post[category_id]">
|
# <select name="post[category_id]">
|
||||||
# <option value="1" disabled="disabled">2008 stuff</option>
|
# <option value="1" disabled="disabled">2008 stuff</option>
|
||||||
# <option value="2" disabled="disabled">Christmas</option>
|
# <option value="2" disabled="disabled">Christmas</option>
|
||||||
# <option value="3">Jokes</option>
|
# <option value="3">Jokes</option>
|
||||||
# <option value="4">Poems</option>
|
# <option value="4">Poems</option>
|
||||||
# </select>
|
# </select>
|
||||||
#
|
#
|
||||||
module FormOptionsHelper
|
module FormOptionsHelper
|
||||||
# ERB::Util can mask some helpers like textilize. Make sure to include them.
|
# ERB::Util can mask some helpers like textilize. Make sure to include them.
|
||||||
|
@ -461,21 +461,7 @@ module ActionView
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a string of <tt><option></tt> tags, like <tt>options_for_select</tt>, but
|
# Returns a string of <tt><option></tt> tags, like <tt>options_for_select</tt>, but
|
||||||
# wraps them with <tt><optgroup></tt> tags.
|
# wraps them with <tt><optgroup></tt> tags:
|
||||||
#
|
|
||||||
# Parameters:
|
|
||||||
# * +grouped_options+ - Accepts a nested array or hash of strings. The first value serves as the
|
|
||||||
# <tt><optgroup></tt> label while the second value must be an array of options. The second value can be a
|
|
||||||
# nested array of text-value pairs. See <tt>options_for_select</tt> for more info.
|
|
||||||
# Ex. ["North America",[["United States","US"],["Canada","CA"]]]
|
|
||||||
# * +selected_key+ - A value equal to the +value+ attribute for one of the <tt><option></tt> tags,
|
|
||||||
# which will have the +selected+ attribute set. Note: It is possible for this value to match multiple options
|
|
||||||
# as you might have the same option in multiple groups. Each will then get <tt>selected="selected"</tt>.
|
|
||||||
#
|
|
||||||
# Options:
|
|
||||||
# * <tt>:prompt</tt> - set to true or a prompt string. When the select element doesn't have a value yet, this
|
|
||||||
# prepends an option with a generic prompt - "Please select" - or the given prompt string.
|
|
||||||
# * <tt>:divider</tt> - the divider for the options groups.
|
|
||||||
#
|
#
|
||||||
# grouped_options = [
|
# grouped_options = [
|
||||||
# ['North America',
|
# ['North America',
|
||||||
|
@ -502,22 +488,36 @@ module ActionView
|
||||||
# <option value="France">France</option>
|
# <option value="France">France</option>
|
||||||
# </optgroup>
|
# </optgroup>
|
||||||
#
|
#
|
||||||
# grouped_options = [
|
# Parameters:
|
||||||
# [['United States','US'], 'Canada'],
|
# * +grouped_options+ - Accepts a nested array or hash of strings. The first value serves as the
|
||||||
# ['Denmark','Germany','France']
|
# <tt><optgroup></tt> label while the second value must be an array of options. The second value can be a
|
||||||
# ]
|
# nested array of text-value pairs. See <tt>options_for_select</tt> for more info.
|
||||||
# grouped_options_for_select(grouped_options, nil, divider: '---------')
|
# Ex. ["North America",[["United States","US"],["Canada","CA"]]]
|
||||||
|
# * +selected_key+ - A value equal to the +value+ attribute for one of the <tt><option></tt> tags,
|
||||||
|
# which will have the +selected+ attribute set. Note: It is possible for this value to match multiple options
|
||||||
|
# as you might have the same option in multiple groups. Each will then get <tt>selected="selected"</tt>.
|
||||||
#
|
#
|
||||||
# Possible output:
|
# Options:
|
||||||
# <optgroup label="---------">
|
# * <tt>:prompt</tt> - set to true or a prompt string. When the select element doesn't have a value yet, this
|
||||||
# <option value="US">United States</option>
|
# prepends an option with a generic prompt - "Please select" - or the given prompt string.
|
||||||
# <option value="Canada">Canada</option>
|
# * <tt>:divider</tt> - the divider for the options groups.
|
||||||
# </optgroup>
|
#
|
||||||
# <optgroup label="---------">
|
# grouped_options = [
|
||||||
# <option value="Denmark">Denmark</option>
|
# [['United States','US'], 'Canada'],
|
||||||
# <option value="Germany">Germany</option>
|
# ['Denmark','Germany','France']
|
||||||
# <option value="France">France</option>
|
# ]
|
||||||
# </optgroup>
|
# grouped_options_for_select(grouped_options, nil, divider: '---------')
|
||||||
|
#
|
||||||
|
# Possible output:
|
||||||
|
# <optgroup label="---------">
|
||||||
|
# <option value="US">United States</option>
|
||||||
|
# <option value="Canada">Canada</option>
|
||||||
|
# </optgroup>
|
||||||
|
# <optgroup label="---------">
|
||||||
|
# <option value="Denmark">Denmark</option>
|
||||||
|
# <option value="Germany">Germany</option>
|
||||||
|
# <option value="France">France</option>
|
||||||
|
# </optgroup>
|
||||||
#
|
#
|
||||||
# <b>Note:</b> Only the <tt><optgroup></tt> and <tt><option></tt> tags are returned, so you still have to
|
# <b>Note:</b> Only the <tt><optgroup></tt> and <tt><option></tt> tags are returned, so you still have to
|
||||||
# wrap the output in an appropriate <tt><select></tt> tag.
|
# wrap the output in an appropriate <tt><select></tt> tag.
|
||||||
|
|
Loading…
Reference in New Issue