Skip to content
Newer
Older
100644 834 lines (793 sloc) 41.2 KB
db045db @dhh Initial
dhh authored Nov 24, 2004
1 require 'cgi'
2 require 'erb'
0eacdcf @jeremy Use a consistent load path to avoid double requires. Fix some scatter…
jeremy authored Jan 28, 2007
3 require 'action_view/helpers/form_helper'
330327e @spastorino Call html_escape in ERB::Util module and don't mix it in in the helpers
spastorino authored Oct 18, 2010
4 require 'active_support/core_ext/string/output_safety'
9c1cd6b @amatsuda Missing or unneeded require extract_options
amatsuda authored Jan 31, 2013
5 require 'active_support/core_ext/array/extract_options'
5d54fd7 @rafaelfranca Add missing require.
rafaelfranca authored Dec 13, 2012
6 require 'active_support/core_ext/array/wrap'
db045db @dhh Initial
dhh authored Nov 24, 2004
7
8 module ActionView
5a0bc2c @rizwanreza Adds title and description where needed.
rizwanreza authored Jun 16, 2010
9 # = Action View Form Option Helpers
db045db @dhh Initial
dhh authored Nov 24, 2004
10 module Helpers
c81af99 @dhh Added the option of passing a block to ActiveRecordHelper#form in ord…
dhh authored Jan 15, 2005
11 # Provides a number of methods for turning different kinds of containers into a set of option tags.
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
12 #
d676a7f @tekin Updated rdoc to reflect changes to form option helpers
tekin authored Feb 14, 2009
13 # The <tt>collection_select</tt>, <tt>select</tt> and <tt>time_zone_select</tt> methods take an <tt>options</tt> parameter, a hash:
96d3f15 @dhh Documentation on :include_blank #579
dhh authored Feb 17, 2005
14 #
b6541b8 @jeremy select :include_blank option can be set to a string instead of true, …
jeremy authored May 18, 2007
15 # * <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.
16 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
17 # select("post", "category", Post::CATEGORIES, {include_blank: true})
96d3f15 @dhh Documentation on :include_blank #579
dhh authored Feb 17, 2005
18 #
0dd4978 @dhh More documentation #1148 [Alisdair McDiarmid]
dhh authored Apr 19, 2005
19 # could become:
96d3f15 @dhh Documentation on :include_blank #579
dhh authored Feb 17, 2005
20 #
21 # <select name="post[category]">
22 # <option></option>
23 # <option>joke</option>
24 # <option>poem</option>
25 # </select>
0dd4978 @dhh More documentation #1148 [Alisdair McDiarmid]
dhh authored Apr 19, 2005
26 #
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
27 # Another common case is a select tag for a <tt>belongs_to</tt>-associated object.
b6541b8 @jeremy select :include_blank option can be set to a string instead of true, …
jeremy authored May 18, 2007
28 #
29 # Example with @post.person_id => 2:
30 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
31 # select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, {include_blank: 'None'})
b6541b8 @jeremy select :include_blank option can be set to a string instead of true, …
jeremy authored May 18, 2007
32 #
33 # could become:
34 #
35 # <select name="post[person_id]">
36 # <option value="">None</option>
37 # <option value="1">David</option>
38 # <option value="2" selected="selected">Sam</option>
39 # <option value="3">Tobias</option>
40 # </select>
41 #
c52edf2 @dhh Added :prompt option to FormOptions#select (and the users of it, like…
dhh authored Jul 3, 2005
42 # * <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.
43 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
44 # select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, {prompt: 'Select Person'})
0dd4978 @dhh More documentation #1148 [Alisdair McDiarmid]
dhh authored Apr 19, 2005
45 #
46 # could become:
47 #
48 # <select name="post[person_id]">
b6541b8 @jeremy select :include_blank option can be set to a string instead of true, …
jeremy authored May 18, 2007
49 # <option value="">Select Person</option>
0dd4978 @dhh More documentation #1148 [Alisdair McDiarmid]
dhh authored Apr 19, 2005
50 # <option value="1">David</option>
51 # <option value="2">Sam</option>
52 # <option value="3">Tobias</option>
53 # </select>
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
54 #
55 # 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
54213da @dhh Docfixes (closes #11356, #11172, #10523)
dhh authored Mar 20, 2008
56 # option to be in the +html_options+ parameter.
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
57 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
58 # select("album[]", "genre", %w[rap rock country], {}, { index: nil })
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
59 #
54213da @dhh Docfixes (closes #11356, #11172, #10523)
dhh authored Mar 20, 2008
60 # becomes:
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
61 #
54213da @dhh Docfixes (closes #11356, #11172, #10523)
dhh authored Mar 20, 2008
62 # <select name="album[][genre]" id="album__genre">
63 # <option value="rap">rap</option>
64 # <option value="rock">rock</option>
65 # <option value="country">country</option>
66 # </select>
d676a7f @tekin Updated rdoc to reflect changes to form option helpers
tekin authored Feb 14, 2009
67 #
68 # * <tt>:disabled</tt> - can be a single value or an array of values that will be disabled options in the final output.
69 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
70 # select("post", "category", Post::CATEGORIES, {disabled: 'restricted'})
d676a7f @tekin Updated rdoc to reflect changes to form option helpers
tekin authored Feb 14, 2009
71 #
72 # could become:
73 #
74 # <select name="post[category]">
75 # <option></option>
76 # <option>joke</option>
77 # <option>poem</option>
78 # <option disabled="disabled">restricted</option>
79 # </select>
80 #
81 # 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.
82 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
83 # collection_select(:post, :category_id, Category.all, :id, :name, {disabled: lambda{|category| category.archived? }})
d676a7f @tekin Updated rdoc to reflect changes to form option helpers
tekin authored Feb 14, 2009
84 #
85 # If the categories "2008 stuff" and "Christmas" return true when the method <tt>archived?</tt> is called, this would return:
86 # <select name="post[category_id]">
87 # <option value="1" disabled="disabled">2008 stuff</option>
88 # <option value="2" disabled="disabled">Christmas</option>
89 # <option value="3">Jokes</option>
90 # <option value="4">Poems</option>
91 # </select>
92 #
db045db @dhh Initial
dhh authored Nov 24, 2004
93 module FormOptionsHelper
7b62278 @wycats Make form helpers work with <%=
wycats authored Mar 9, 2010
94 # ERB::Util can mask some helpers like textilize. Make sure to include them.
95 include TextHelper
df28bdd @dhh Documented select, collection_select, and country_select #304 [Ulysses]
dhh authored Dec 15, 2004
96
97 # Create a select tag and a series of contained option tags for the provided object and method.
098fa94 @dhh Fixed documentation snafus #575, #576, #577, #585
dhh authored Feb 7, 2005
98 # The option currently held by the object will be selected, provided that the object is available.
587dd7d @AndrewRadev Grouped select helper
AndrewRadev authored Jun 14, 2011
99 #
100 # There are two possible formats for the choices parameter, corresponding to other helpers' output:
101 # * A flat collection: see options_for_select
102 # * A nested collection: see grouped_options_for_select
0dd4978 @dhh More documentation #1148 [Alisdair McDiarmid]
dhh authored Apr 19, 2005
103 #
104 # Example with @post.person_id => 1:
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
105 # select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, { include_blank: true })
0dd4978 @dhh More documentation #1148 [Alisdair McDiarmid]
dhh authored Apr 19, 2005
106 #
107 # could become:
108 #
d933627 @jeremy Introduce :selected option to the select helper. Allows you to specif…
jeremy authored Nov 23, 2005
109 # <select name="post[person_id]">
b6541b8 @jeremy select :include_blank option can be set to a string instead of true, …
jeremy authored May 18, 2007
110 # <option value=""></option>
0dd4978 @dhh More documentation #1148 [Alisdair McDiarmid]
dhh authored Apr 19, 2005
111 # <option value="1" selected="selected">David</option>
112 # <option value="2">Sam</option>
113 # <option value="3">Tobias</option>
114 # </select>
dfac1ce @dhh Fixed that form helpers would treat string and symbol keys differentl…
dhh authored Mar 6, 2005
115 #
df28bdd @dhh Documented select, collection_select, and country_select #304 [Ulysses]
dhh authored Dec 15, 2004
116 # This can be used to provide a default set of options in the standard way: before rendering the create form, a
117 # new model instance is assigned the default options and bound to @model_name. Usually this model is not saved
118 # to the database. Instead, a second model object is created when the create request is received.
119 # This allows the user to submit a form page more than once with the expected results of creating multiple records.
120 # In addition, this allows a single partial to be used to generate form inputs for both edit and create forms.
d933627 @jeremy Introduce :selected option to the select helper. Allows you to specif…
jeremy authored Nov 23, 2005
121 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
122 # By default, <tt>post.person_id</tt> is the selected option. Specify <tt>selected: value</tt> to use a different selection
123 # or <tt>selected: nil</tt> to leave all options unselected. Similarly, you can specify values to be disabled in the option
d676a7f @tekin Updated rdoc to reflect changes to form option helpers
tekin authored Feb 14, 2009
124 # tags by specifying the <tt>:disabled</tt> option. This can either be a single value or an array of values to be disabled.
faba406 @bogdan Fixing select[multiple] html specification problem.
bogdan authored Jun 8, 2011
125 #
126 # ==== Gotcha
127 #
2e487bc @rafaelfranca Whitespaces :scissors:
rafaelfranca authored Jan 5, 2012
128 # The HTML specification says when +multiple+ parameter passed to select and all options got deselected
faba406 @bogdan Fixing select[multiple] html specification problem.
bogdan authored Jun 8, 2011
129 # web browsers do not send any value to server. Unfortunately this introduces a gotcha:
130 # if an +User+ model has many +roles+ and have +role_ids+ accessor, and in the form that edits roles of the user
131 # the user deselects all roles from +role_ids+ multiple select box, no +role_ids+ parameter is sent. So,
132 # any mass-assignment idiom like
133 #
1bb0200 Change docs to use update instead of update_attributes
Amparo Luna + Guillermo Iguaran authored Jan 2, 2013
134 # @user.update(params[:user])
faba406 @bogdan Fixing select[multiple] html specification problem.
bogdan authored Jun 8, 2011
135 #
136 # wouldn't update roles.
137 #
138 # To prevent this the helper generates an auxiliary hidden field before
139 # every multiple select. The hidden field has the same name as multiple select and blank value.
140 #
141 # This way, the client either sends only the hidden field (representing
142 # the deselected multiple select box), or both fields. Since the HTML specification
143 # says key/value pairs have to be sent in the same order they appear in the
144 # form, and parameters extraction gets the last occurrence of any repeated
145 # key in the query string, that works for ordinary forms.
146 #
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
147 # In case if you don't want the helper to generate this hidden field you can specify
148 # <tt>include_hidden: false</tt> option.
54a75e1 @nashby add 'include_hidden' option to select tag, closes #5402
nashby authored Mar 13, 2012
149 #
db045db @dhh Initial
dhh authored Nov 24, 2004
150 def select(object, method, choices, options = {}, html_options = {})
8b4c74f @rafaelfranca Do not need of ActionView::Helpers scope since we are inside
rafaelfranca authored Jan 17, 2012
151 Tags::Select.new(object, method, self, choices, options, html_options).render
db045db @dhh Initial
dhh authored Nov 24, 2004
152 end
dfac1ce @dhh Fixed that form helpers would treat string and symbol keys differentl…
dhh authored Mar 6, 2005
153
b59e3d1 @NZKoz Major improvement to the documentation for the options / select form…
NZKoz authored Aug 5, 2007
154 # Returns <tt><select></tt> and <tt><option></tt> tags for the collection of existing return values of
155 # +method+ for +object+'s class. The value returned from calling +method+ on the instance +object+ will
156 # be selected. If calling +method+ returns +nil+, no selection is made without including <tt>:prompt</tt>
157 # or <tt>:include_blank</tt> in the +options+ hash.
158 #
159 # The <tt>:value_method</tt> and <tt>:text_method</tt> parameters are methods to be called on each member
160 # of +collection+. The return values are used as the +value+ attribute and contents of each
f506c80 @carlosantoniodasilva Add changelog, docs and guides entries
carlosantoniodasilva authored Feb 1, 2012
161 # <tt><option></tt> tag, respectively. They can also be any object that responds to +call+, such
162 # as a +proc+, that will be called for each member of the +collection+ to
163 # retrieve the value/text.
b451de0 @spastorino Deletes trailing whitespaces (over text files only find * -type f -ex…
spastorino authored Aug 14, 2010
164 #
b59e3d1 @NZKoz Major improvement to the documentation for the options / select form…
NZKoz authored Aug 5, 2007
165 # Example object structure for use with this method:
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
166 #
b59e3d1 @NZKoz Major improvement to the documentation for the options / select form…
NZKoz authored Aug 5, 2007
167 # class Post < ActiveRecord::Base
168 # belongs_to :author
169 # end
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
170 #
b59e3d1 @NZKoz Major improvement to the documentation for the options / select form…
NZKoz authored Aug 5, 2007
171 # class Author < ActiveRecord::Base
172 # has_many :posts
173 # def name_with_initial
174 # "#{first_name.first}. #{last_name}"
175 # end
176 # end
177 #
98dc582 @lifo Merge docrails.
lifo authored May 25, 2008
178 # Sample usage (selecting the associated Author for an instance of Post, <tt>@post</tt>):
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
179 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
180 # collection_select(:post, :author_id, Author.all, :id, :name_with_initial, prompt: true)
b59e3d1 @NZKoz Major improvement to the documentation for the options / select form…
NZKoz authored Aug 5, 2007
181 #
182 # If <tt>@post.author_id</tt> is already <tt>1</tt>, this would return:
183 # <select name="post[author_id]">
184 # <option value="">Please select</option>
185 # <option value="1" selected="selected">D. Heinemeier Hansson</option>
186 # <option value="2">D. Thomas</option>
187 # <option value="3">M. Clark</option>
188 # </select>
db045db @dhh Initial
dhh authored Nov 24, 2004
189 def collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})
8b4c74f @rafaelfranca Do not need of ActionView::Helpers scope since we are inside
rafaelfranca authored Jan 17, 2012
190 Tags::CollectionSelect.new(object, method, self, collection, value_method, text_method, options, html_options).render
db045db @dhh Initial
dhh authored Nov 24, 2004
191 end
dfac1ce @dhh Fixed that form helpers would treat string and symbol keys differentl…
dhh authored Mar 6, 2005
192
8c32248 Introduce grouped_collection_select helper.
codeape authored Aug 9, 2009
193 # Returns <tt><select></tt>, <tt><optgroup></tt> and <tt><option></tt> tags for the collection of existing return values of
194 # +method+ for +object+'s class. The value returned from calling +method+ on the instance +object+ will
195 # be selected. If calling +method+ returns +nil+, no selection is made without including <tt>:prompt</tt>
196 # or <tt>:include_blank</tt> in the +options+ hash.
197 #
198 # Parameters:
199 # * +object+ - The instance of the class to be used for the select tag
200 # * +method+ - The attribute of +object+ corresponding to the select tag
201 # * +collection+ - An array of objects representing the <tt><optgroup></tt> tags.
202 # * +group_method+ - The name of a method which, when called on a member of +collection+, returns an
203 # array of child objects representing the <tt><option></tt> tags.
204 # * +group_label_method+ - The name of a method which, when called on a member of +collection+, returns a
205 # string to be used as the +label+ attribute for its <tt><optgroup></tt> tag.
206 # * +option_key_method+ - The name of a method which, when called on a child object of a member of
207 # +collection+, returns a value to be used as the +value+ attribute for its <tt><option></tt> tag.
208 # * +option_value_method+ - The name of a method which, when called on a child object of a member of
209 # +collection+, returns a value to be used as the contents of its <tt><option></tt> tag.
210 #
211 # Example object structure for use with this method:
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
212 #
8c32248 Introduce grouped_collection_select helper.
codeape authored Aug 10, 2009
213 # class Continent < ActiveRecord::Base
214 # has_many :countries
215 # # attribs: id, name
216 # end
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
217 #
8c32248 Introduce grouped_collection_select helper.
codeape authored Aug 10, 2009
218 # class Country < ActiveRecord::Base
219 # belongs_to :continent
220 # # attribs: id, name, continent_id
221 # end
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
222 #
8c32248 Introduce grouped_collection_select helper.
codeape authored Aug 10, 2009
223 # class City < ActiveRecord::Base
224 # belongs_to :country
225 # # attribs: id, name, country_id
226 # end
227 #
228 # Sample usage:
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
229 #
8c32248 Introduce grouped_collection_select helper.
codeape authored Aug 10, 2009
230 # grouped_collection_select(:city, :country_id, @continents, :countries, :name, :id, :name)
231 #
232 # Possible output:
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
233 #
8c32248 Introduce grouped_collection_select helper.
codeape authored Aug 10, 2009
234 # <select name="city[country_id]">
235 # <optgroup label="Africa">
236 # <option value="1">South Africa</option>
237 # <option value="3">Somalia</option>
238 # </optgroup>
239 # <optgroup label="Europe">
240 # <option value="7" selected="selected">Denmark</option>
241 # <option value="2">Ireland</option>
242 # </optgroup>
243 # </select>
244 #
245 def grouped_collection_select(object, method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
8b4c74f @rafaelfranca Do not need of ActionView::Helpers scope since we are inside
rafaelfranca authored Jan 17, 2012
246 Tags::GroupedCollectionSelect.new(object, method, self, collection, group_method, group_label_method, option_key_method, option_value_method, options, html_options).render
8c32248 Introduce grouped_collection_select helper.
codeape authored Aug 10, 2009
247 end
248
2bf29b3 @dhh Added FormOptionsHelper#time_zone_select and FormOptionsHelper#time_z…
dhh authored Feb 23, 2005
249 # Return select and option tags for the given object and method, using
250 # #time_zone_options_for_select to generate the list of option tags.
251 #
252 # In addition to the <tt>:include_blank</tt> option documented above,
253 # this method also supports a <tt>:model</tt> option, which defaults
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
254 # to ActiveSupport::TimeZone. This may be used by users to specify a
255 # different time zone model object. (See +time_zone_options_for_select+
256 # for more information.)
0f33344 @gbuesing time_zone_select docs: explain priority zones option. Add example sho…
gbuesing authored May 18, 2008
257 #
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
258 # You can also supply an array of ActiveSupport::TimeZone objects
0f33344 @gbuesing time_zone_select docs: explain priority zones option. Add example sho…
gbuesing authored May 18, 2008
259 # as +priority_zones+, so that they will be listed above the rest of the
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
260 # (long) list. (You can use ActiveSupport::TimeZone.us_zones as a convenience
261 # for obtaining a list of the US time zones, or a Regexp to select the zones
d0092dc @ernie Added support for regexp matching of priority zones in time_zone_sele…
ernie authored Jun 28, 2008
262 # of your choice)
0f33344 @gbuesing time_zone_select docs: explain priority zones option. Add example sho…
gbuesing authored May 18, 2008
263 #
a81333f @jeremy Add :default option to time_zone_select. Closes #10590.
jeremy authored Dec 21, 2007
264 # Finally, this method supports a <tt>:default</tt> option, which selects
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
265 # a default ActiveSupport::TimeZone if the object's time zone is +nil+.
a81333f @jeremy Add :default option to time_zone_select. Closes #10590.
jeremy authored Dec 21, 2007
266 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
267 # time_zone_select( "user", "time_zone", nil, include_blank: true)
a81333f @jeremy Add :default option to time_zone_select. Closes #10590.
jeremy authored Dec 21, 2007
268 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
269 # time_zone_select( "user", "time_zone", nil, default: "Pacific Time (US & Canada)" )
a81333f @jeremy Add :default option to time_zone_select. Closes #10590.
jeremy authored Dec 21, 2007
270 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
271 # time_zone_select( "user", 'time_zone', ActiveSupport::TimeZone.us_zones, default: "Pacific Time (US & Canada)")
a81333f @jeremy Add :default option to time_zone_select. Closes #10590.
jeremy authored Dec 21, 2007
272 #
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
273 # time_zone_select( "user", 'time_zone', [ ActiveSupport::TimeZone['Alaska'], ActiveSupport::TimeZone['Hawaii'] ])
0f33344 @gbuesing time_zone_select docs: explain priority zones option. Add example sho…
gbuesing authored May 18, 2008
274 #
d0092dc @ernie Added support for regexp matching of priority zones in time_zone_sele…
ernie authored Jun 29, 2008
275 # time_zone_select( "user", 'time_zone', /Australia/)
276 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
277 # time_zone_select( "user", "time_zone", ActiveSupport::TimeZone.all.sort, model: ActiveSupport::TimeZone)
2bf29b3 @dhh Added FormOptionsHelper#time_zone_select and FormOptionsHelper#time_z…
dhh authored Feb 23, 2005
278 def time_zone_select(object, method, priority_zones = nil, options = {}, html_options = {})
8b4c74f @rafaelfranca Do not need of ActionView::Helpers scope since we are inside
rafaelfranca authored Jan 17, 2012
279 Tags::TimeZoneSelect.new(object, method, self, priority_zones, options, html_options).render
2bf29b3 @dhh Added FormOptionsHelper#time_zone_select and FormOptionsHelper#time_z…
dhh authored Feb 23, 2005
280 end
281
dfac1ce @dhh Fixed that form helpers would treat string and symbol keys differentl…
dhh authored Mar 6, 2005
282 # Accepts a container (hash, array, enumerable, your type) and returns a string of option tags. Given a container
db045db @dhh Initial
dhh authored Nov 24, 2004
283 # where the elements respond to first and last (such as a two-element array), the "lasts" serve as option values and
284 # the "firsts" as option text. Hashes are turned into this form automatically, so the keys become "firsts" and values
fcdb5dc @smartinez87 Remove extra white spaces on ActionPack docs.
smartinez87 authored May 23, 2011
285 # become lasts. If +selected+ is specified, the matching "last" or element will get the selected option-tag. +selected+
dfac1ce @dhh Fixed that form helpers would treat string and symbol keys differentl…
dhh authored Mar 6, 2005
286 # may also be an array of values to be selected when using a multiple select.
db045db @dhh Initial
dhh authored Nov 24, 2004
287 #
288 # options_for_select([["Dollar", "$"], ["Kroner", "DKK"]])
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
289 # # => <option value="$">Dollar</option>
290 # # => <option value="DKK">Kroner</option>
db045db @dhh Initial
dhh authored Nov 24, 2004
291 #
098fa94 @dhh Fixed documentation snafus #575, #576, #577, #585
dhh authored Feb 7, 2005
292 # options_for_select([ "VISA", "MasterCard" ], "MasterCard")
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
293 # # => <option>VISA</option>
294 # # => <option selected="selected">MasterCard</option>
db045db @dhh Initial
dhh authored Nov 24, 2004
295 #
296 # options_for_select({ "Basic" => "$20", "Plus" => "$40" }, "$40")
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
297 # # => <option value="$20">Basic</option>
298 # # => <option value="$40" selected="selected">Plus</option>
db045db @dhh Initial
dhh authored Nov 24, 2004
299 #
098fa94 @dhh Fixed documentation snafus #575, #576, #577, #585
dhh authored Feb 7, 2005
300 # options_for_select([ "VISA", "MasterCard", "Discover" ], ["VISA", "Discover"])
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
301 # # => <option selected="selected">VISA</option>
302 # # => <option>MasterCard</option>
303 # # => <option selected="selected">Discover</option>
b6854c6 @dhh Added Iran and Irak to the countries list used by FormOptions#country…
dhh authored Feb 19, 2005
304 #
2dc1402 @pleax added support for html attributes in options_for_select [#2165]
pleax authored May 15, 2010
305 # You can optionally provide html attributes as the last element of the array.
306 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
307 # options_for_select([ "Denmark", ["USA", {class: 'bold'}], "Sweden" ], ["USA", "Sweden"])
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
308 # # => <option value="Denmark">Denmark</option>
309 # # => <option value="USA" class="bold" selected="selected">USA</option>
310 # # => <option value="Sweden" selected="selected">Sweden</option>
2dc1402 @pleax added support for html attributes in options_for_select [#2165]
pleax authored May 15, 2010
311 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
312 # options_for_select([["Dollar", "$", {class: "bold"}], ["Kroner", "DKK", {onclick: "alert('HI');"}]])
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
313 # # => <option value="$" class="bold">Dollar</option>
314 # # => <option value="DKK" onclick="alert('HI');">Kroner</option>
2dc1402 @pleax added support for html attributes in options_for_select [#2165]
pleax authored May 15, 2010
315 #
d676a7f @tekin Updated rdoc to reflect changes to form option helpers
tekin authored Feb 14, 2009
316 # If you wish to specify disabled option tags, set +selected+ to be a hash, with <tt>:disabled</tt> being either a value
317 # or array of values to be disabled. In this case, you can use <tt>:selected</tt> to specify selected option tags.
318 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
319 # options_for_select(["Free", "Basic", "Advanced", "Super Platinum"], disabled: "Super Platinum")
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
320 # # => <option value="Free">Free</option>
321 # # => <option value="Basic">Basic</option>
322 # # => <option value="Advanced">Advanced</option>
323 # # => <option value="Super Platinum" disabled="disabled">Super Platinum</option>
d676a7f @tekin Updated rdoc to reflect changes to form option helpers
tekin authored Feb 14, 2009
324 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
325 # options_for_select(["Free", "Basic", "Advanced", "Super Platinum"], disabled: ["Advanced", "Super Platinum"])
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
326 # # => <option value="Free">Free</option>
327 # # => <option value="Basic">Basic</option>
328 # # => <option value="Advanced" disabled="disabled">Advanced</option>
329 # # => <option value="Super Platinum" disabled="disabled">Super Platinum</option>
d676a7f @tekin Updated rdoc to reflect changes to form option helpers
tekin authored Feb 14, 2009
330 #
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
331 # options_for_select(["Free", "Basic", "Advanced", "Super Platinum"], selected: "Free", disabled: "Super Platinum")
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
332 # # => <option value="Free" selected="selected">Free</option>
333 # # => <option value="Basic">Basic</option>
334 # # => <option value="Advanced">Advanced</option>
335 # # => <option value="Super Platinum" disabled="disabled">Super Platinum</option>
d676a7f @tekin Updated rdoc to reflect changes to form option helpers
tekin authored Feb 14, 2009
336 #
b6854c6 @dhh Added Iran and Irak to the countries list used by FormOptions#country…
dhh authored Feb 19, 2005
337 # NOTE: Only the option tags are returned, you have to wrap this call in a regular HTML select tag.
db045db @dhh Initial
dhh authored Nov 24, 2004
338 def options_for_select(container, selected = nil)
eb02170 @josevalim Allow strings to be sent as collection to select.
josevalim authored Apr 1, 2009
339 return container if String === container
340
2ed1797 @rafaelfranca Change more Array.wrap to Kernel#Array
rafaelfranca authored Jan 5, 2012
341 selected, disabled = extract_selected_and_disabled(selected).map do |r|
342 Array(r).map { |item| item.to_s }
54477c9 @subbarao select tags coerce the :selected option, options to strings before co…
subbarao authored Aug 14, 2010
343 end
dfac1ce @dhh Fixed that form helpers would treat string and symbol keys differentl…
dhh authored Mar 6, 2005
344
54477c9 @subbarao select tags coerce the :selected option, options to strings before co…
subbarao authored Aug 14, 2010
345 container.map do |element|
2dc1402 @pleax added support for html attributes in options_for_select [#2165]
pleax authored May 15, 2010
346 html_attributes = option_html_attributes(element)
8faeed1 @christos Improve performance and memory usage for options_for_select with Ruby…
christos authored Jul 27, 2011
347 text, value = option_text_and_value(element).map { |item| item.to_s }
decff3f @nashby refactor options_for_select
nashby authored Feb 20, 2012
348
349 html_attributes[:selected] = 'selected' if option_value_selected?(value, selected)
350 html_attributes[:disabled] = 'disabled' if disabled && option_value_selected?(value, disabled)
351 html_attributes[:value] = value
352
1a935ad Fixed bug creating invalid HTML in select options
Rusty Geldmacher authored Jul 10, 2012
353 content_tag_string(:option, text, html_attributes)
54477c9 @subbarao select tags coerce the :selected option, options to strings before co…
subbarao authored Aug 14, 2010
354 end.join("\n").html_safe
db045db @dhh Initial
dhh authored Nov 24, 2004
355 end
356
4af62c0 @carlosantoniodasilva Remove eval calls, use send.. eval is evil
carlosantoniodasilva authored Jan 25, 2012
357 # Returns a string of option tags that have been compiled by iterating over the +collection+ and assigning
db045db @dhh Initial
dhh authored Nov 24, 2004
358 # the result of a call to the +value_method+ as the option value and the +text_method+ as the option text.
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
359 #
c3f53f4 @lifo Merge docrails
lifo authored Dec 19, 2008
360 # options_from_collection_for_select(@people, 'id', 'name')
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
361 # # => <option value="#{person.id}">#{person.name}</option>
db045db @dhh Initial
dhh authored Nov 24, 2004
362 #
c3f53f4 @lifo Merge docrails
lifo authored Dec 19, 2008
363 # This is more often than not used inside a #select_tag like this example:
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
364 #
c3f53f4 @lifo Merge docrails
lifo authored Dec 19, 2008
365 # select_tag 'person', options_from_collection_for_select(@people, 'id', 'name')
b6854c6 @dhh Added Iran and Irak to the countries list used by FormOptions#country…
dhh authored Feb 19, 2005
366 #
d676a7f @tekin Updated rdoc to reflect changes to form option helpers
tekin authored Feb 14, 2009
367 # If +selected+ is specified as a value or array of values, the element(s) returning a match on +value_method+
368 # will be selected option tag(s).
369 #
370 # If +selected+ is specified as a Proc, those members of the collection that return true for the anonymous
371 # function are the selected values.
372 #
373 # +selected+ can also be a hash, specifying both <tt>:selected</tt> and/or <tt>:disabled</tt> values as required.
374 #
375 # Be sure to specify the same class as the +value_method+ when specifying selected or disabled options.
c3f53f4 @lifo Merge docrails
lifo authored Dec 19, 2008
376 # Failure to do this will produce undesired results. Example:
377 # options_from_collection_for_select(@people, 'id', 'name', '1')
378 # Will not select a person with the id of 1 because 1 (an Integer) is not the same as '1' (a string)
379 # options_from_collection_for_select(@people, 'id', 'name', 1)
380 # should produce the desired results.
3edc98a @jeremy form_options_helper refactoring for clarity. Closes #7787.
jeremy authored Mar 11, 2007
381 def options_from_collection_for_select(collection, value_method, text_method, selected = nil)
382 options = collection.map do |element|
0778290 @nashby options_from_collection_for_select helper takes html attributes
nashby authored Apr 11, 2013
383 [value_for_collection(element, text_method), value_for_collection(element, value_method), option_html_attributes(element)]
3edc98a @jeremy form_options_helper refactoring for clarity. Closes #7787.
jeremy authored Mar 11, 2007
384 end
1525f38 @tekin Enhanced form option helpers to add support for disabled option tags …
tekin authored Feb 14, 2009
385 selected, disabled = extract_selected_and_disabled(selected)
4a18cbb @carlosantoniodasilva Cleanup options helper methods a bit
carlosantoniodasilva authored Jan 31, 2012
386 select_deselect = {
387 :selected => extract_values_from_collection(collection, value_method, selected),
388 :disabled => extract_values_from_collection(collection, value_method, disabled)
389 }
1525f38 @tekin Enhanced form option helpers to add support for disabled option tags …
tekin authored Feb 14, 2009
390
391 options_for_select(options, select_deselect)
db045db @dhh Initial
dhh authored Nov 24, 2004
392 end
393
98dc582 @lifo Merge docrails.
lifo authored May 25, 2008
394 # Returns a string of <tt><option></tt> tags, like <tt>options_from_collection_for_select</tt>, but
b59e3d1 @NZKoz Major improvement to the documentation for the options / select form…
NZKoz authored Aug 5, 2007
395 # groups them by <tt><optgroup></tt> tags based on the object relationships of the arguments.
396 #
397 # Parameters:
98dc582 @lifo Merge docrails.
lifo authored May 25, 2008
398 # * +collection+ - An array of objects representing the <tt><optgroup></tt> tags.
399 # * +group_method+ - The name of a method which, when called on a member of +collection+, returns an
400 # array of child objects representing the <tt><option></tt> tags.
401 # * group_label_method+ - The name of a method which, when called on a member of +collection+, returns a
402 # string to be used as the +label+ attribute for its <tt><optgroup></tt> tag.
403 # * +option_key_method+ - The name of a method which, when called on a child object of a member of
404 # +collection+, returns a value to be used as the +value+ attribute for its <tt><option></tt> tag.
405 # * +option_value_method+ - The name of a method which, when called on a child object of a member of
406 # +collection+, returns a value to be used as the contents of its <tt><option></tt> tag.
407 # * +selected_key+ - A value equal to the +value+ attribute for one of the <tt><option></tt> tags,
408 # which will have the +selected+ attribute set. Corresponds to the return value of one of the calls
d676a7f @tekin Updated rdoc to reflect changes to form option helpers
tekin authored Feb 14, 2009
409 # to +option_key_method+. If +nil+, no selection is made. Can also be a hash if disabled values are
410 # to be specified.
b59e3d1 @NZKoz Major improvement to the documentation for the options / select form…
NZKoz authored Aug 5, 2007
411 #
412 # Example object structure for use with this method:
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
413 #
b59e3d1 @NZKoz Major improvement to the documentation for the options / select form…
NZKoz authored Aug 5, 2007
414 # class Continent < ActiveRecord::Base
415 # has_many :countries
416 # # attribs: id, name
417 # end
4940d6d @alvaropereyra Cleans and removes useless 'Examples' tag [ci skip]
alvaropereyra authored Dec 1, 2012
418 #
b59e3d1 @NZKoz Major improvement to the documentation for the options / select form…
NZKoz authored Aug 5, 2007
419 # class Country < ActiveRecord::Base
420 # belongs_to :continent
421 # # attribs: id, name, continent_id
422 # end
423 #
424 # Sample usage:
425 # option_groups_from_collection_for_select(@continents, :countries, :name, :id, :name, 3)
426 #
427 # Possible output:
428 # <optgroup label="Africa">
429 # <option value="1">Egypt</option>
430 # <option value="4">Rwanda</option>
431 # ...
432 # </optgroup>
433 # <optgroup label="Asia">
434 # <option value="3" selected="selected">China</option>
435 # <option value="12">India</option>
436 # <option value="5">Japan</option>
437 # ...
438 # </optgroup>
439 #
440 # <b>Note:</b> Only the <tt><optgroup></tt> and <tt><option></tt> tags are returned, so you still have to
441 # wrap the output in an appropriate <tt><select></tt> tag.
442 def option_groups_from_collection_for_select(collection, group_method, group_label_method, option_key_method, option_value_method, selected_key = nil)
1ef2b47 @tenderlove convert inject to map + join
tenderlove authored Sep 28, 2010
443 collection.map do |group|
595271c @carlosantoniodasilva Refactor option groups to use content_tag
carlosantoniodasilva authored Jan 31, 2012
444 option_tags = options_from_collection_for_select(
445 group.send(group_method), option_key_method, option_value_method, selected_key)
446
447 content_tag(:optgroup, option_tags, :label => group.send(group_label_method))
1ef2b47 @tenderlove convert inject to map + join
tenderlove authored Sep 28, 2010
448 end.join.html_safe
dfac1ce @dhh Fixed that form helpers would treat string and symbol keys differentl…
dhh authored Mar 6, 2005
449 end
450
8761663 @JonCrawford Added grouped_options_for_select helper method for wrapping option ta…
JonCrawford authored Jan 29, 2009
451 # Returns a string of <tt><option></tt> tags, like <tt>options_for_select</tt>, but
452 # wraps them with <tt><optgroup></tt> tags.
453 #
454 # Parameters:
fcdb5dc @smartinez87 Remove extra white spaces on ActionPack docs.
smartinez87 authored May 23, 2011
455 # * +grouped_options+ - Accepts a nested array or hash of strings. The first value serves as the
8761663 @JonCrawford Added grouped_options_for_select helper method for wrapping option ta…
JonCrawford authored Jan 29, 2009
456 # <tt><optgroup></tt> label while the second value must be an array of options. The second value can be a
457 # nested array of text-value pairs. See <tt>options_for_select</tt> for more info.
458 # Ex. ["North America",[["United States","US"],["Canada","CA"]]]
459 # * +selected_key+ - A value equal to the +value+ attribute for one of the <tt><option></tt> tags,
460 # which will have the +selected+ attribute set. Note: It is possible for this value to match multiple options
fcdb5dc @smartinez87 Remove extra white spaces on ActionPack docs.
smartinez87 authored May 23, 2011
461 # as you might have the same option in multiple groups. Each will then get <tt>selected="selected"</tt>.
6f04975 @rafaelfranca Test deprecation and fix the documentation of grouped_options_for_select
rafaelfranca authored May 16, 2012
462 #
463 # Options:
464 # * <tt>:prompt</tt> - set to true or a prompt string. When the select element doesn't have a value yet, this
ccf9577 @dolzenko Fix a bunch of minor spelling mistakes
dolzenko authored Jun 11, 2010
465 # prepends an option with a generic prompt - "Please select" - or the given prompt string.
1f0e2de @rafaelfranca Document the usage of grouped_options_for_select with divider option
rafaelfranca authored May 16, 2012
466 # * <tt>:divider</tt> - the divider for the options groups.
8761663 @JonCrawford Added grouped_options_for_select helper method for wrapping option ta…
JonCrawford authored Jan 29, 2009
467 #
468 # grouped_options = [
469 # ['North America',
470 # [['United States','US'],'Canada']],
471 # ['Europe',
472 # ['Denmark','Germany','France']]
473 # ]
474 # grouped_options_for_select(grouped_options)
475 #
476 # grouped_options = {
0e207a4 @carlosantoniodasilva Clarify grouped_options_for_select method API, add changelog entry
carlosantoniodasilva authored May 19, 2012
477 # 'North America' => [['United States','US'], 'Canada'],
478 # 'Europe' => ['Denmark','Germany','France']
8761663 @JonCrawford Added grouped_options_for_select helper method for wrapping option ta…
JonCrawford authored Jan 29, 2009
479 # }
480 # grouped_options_for_select(grouped_options)
481 #
482 # Possible output:
0195d61 @skojin No sort Hash options in #grouped_options_for_select
skojin authored Nov 27, 2012
483 # <optgroup label="North America">
484 # <option value="US">United States</option>
485 # <option value="Canada">Canada</option>
486 # </optgroup>
8761663 @JonCrawford Added grouped_options_for_select helper method for wrapping option ta…
JonCrawford authored Jan 29, 2009
487 # <optgroup label="Europe">
488 # <option value="Denmark">Denmark</option>
489 # <option value="Germany">Germany</option>
490 # <option value="France">France</option>
491 # </optgroup>
492 #
1f0e2de @rafaelfranca Document the usage of grouped_options_for_select with divider option
rafaelfranca authored May 17, 2012
493 # grouped_options = [
0e207a4 @carlosantoniodasilva Clarify grouped_options_for_select method API, add changelog entry
carlosantoniodasilva authored May 19, 2012
494 # [['United States','US'], 'Canada'],
495 # ['Denmark','Germany','France']
1f0e2de @rafaelfranca Document the usage of grouped_options_for_select with divider option
rafaelfranca authored May 17, 2012
496 # ]
0e207a4 @carlosantoniodasilva Clarify grouped_options_for_select method API, add changelog entry
carlosantoniodasilva authored May 19, 2012
497 # grouped_options_for_select(grouped_options, nil, divider: '---------')
1f0e2de @rafaelfranca Document the usage of grouped_options_for_select with divider option
rafaelfranca authored May 17, 2012
498 #
499 # Possible output:
500 # <optgroup label="---------">
7c58425 @evanfarrar Make a doc example output in match actual output
evanfarrar authored Aug 15, 2012
501 # <option value="US">United States</option>
502 # <option value="Canada">Canada</option>
503 # </optgroup>
504 # <optgroup label="---------">
1f0e2de @rafaelfranca Document the usage of grouped_options_for_select with divider option
rafaelfranca authored May 17, 2012
505 # <option value="Denmark">Denmark</option>
506 # <option value="Germany">Germany</option>
507 # <option value="France">France</option>
508 # </optgroup>
509 #
8761663 @JonCrawford Added grouped_options_for_select helper method for wrapping option ta…
JonCrawford authored Jan 29, 2009
510 # <b>Note:</b> Only the <tt><optgroup></tt> and <tt><option></tt> tags are returned, so you still have to
511 # wrap the output in an appropriate <tt><select></tt> tag.
0e207a4 @carlosantoniodasilva Clarify grouped_options_for_select method API, add changelog entry
carlosantoniodasilva authored May 19, 2012
512 def grouped_options_for_select(grouped_options, selected_key = nil, options = {})
513 if options.is_a?(Hash)
514 prompt = options[:prompt]
a1ae17e @Greenie0506 Add separator argument to grouped_options_for_select
Greenie0506 authored May 15, 2012
515 divider = options[:divider]
0e207a4 @carlosantoniodasilva Clarify grouped_options_for_select method API, add changelog entry
carlosantoniodasilva authored May 19, 2012
516 else
517 prompt = options
518 options = {}
008154e @carlosantoniodasilva Fix failing tests and use new hash style in deprecation messages
carlosantoniodasilva authored Oct 29, 2012
519 message = "Passing the prompt to grouped_options_for_select as an argument is deprecated. " \
0b7067d @nikitug Provide a call stack for deprecation warnings where needed.
nikitug authored Oct 29, 2012
520 "Please use an options hash like `{ prompt: #{prompt.inspect} }`."
b955939 @gazay Make caller attribute in deprecation methods optional
gazay authored Oct 30, 2012
521 ActiveSupport::Deprecation.warn message
a1ae17e @Greenie0506 Add separator argument to grouped_options_for_select
Greenie0506 authored May 15, 2012
522 end
523
421025f @nashby refactor grouped_options_for_select
nashby authored Feb 20, 2012
524 body = "".html_safe
982ed06 @rafaelfranca Make :prompt work as documented
rafaelfranca authored May 16, 2012
525
526 if prompt
527 body.safe_concat content_tag(:option, prompt_text(prompt), :value => "")
528 end
8761663 @JonCrawford Added grouped_options_for_select helper method for wrapping option ta…
JonCrawford authored Jan 29, 2009
529
a1ae17e @Greenie0506 Add separator argument to grouped_options_for_select
Greenie0506 authored May 15, 2012
530 grouped_options.each do |container|
531 if divider
0e207a4 @carlosantoniodasilva Clarify grouped_options_for_select method API, add changelog entry
carlosantoniodasilva authored May 19, 2012
532 label = divider
a1ae17e @Greenie0506 Add separator argument to grouped_options_for_select
Greenie0506 authored May 15, 2012
533 else
534 label, container = container
535 end
421025f @nashby refactor grouped_options_for_select
nashby authored Feb 20, 2012
536 body.safe_concat content_tag(:optgroup, options_for_select(container, selected_key), :label => label)
8761663 @JonCrawford Added grouped_options_for_select helper method for wrapping option ta…
JonCrawford authored Jan 29, 2009
537 end
538
421025f @nashby refactor grouped_options_for_select
nashby authored Feb 20, 2012
539 body
8761663 @JonCrawford Added grouped_options_for_select helper method for wrapping option ta…
JonCrawford authored Jan 29, 2009
540 end
541
2bf29b3 @dhh Added FormOptionsHelper#time_zone_select and FormOptionsHelper#time_z…
dhh authored Feb 23, 2005
542 # Returns a string of option tags for pretty much any time zone in the
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
543 # world. Supply a ActiveSupport::TimeZone name as +selected+ to have it
544 # marked as the selected option tag. You can also supply an array of
545 # ActiveSupport::TimeZone objects as +priority_zones+, so that they will
546 # be listed above the rest of the (long) list. (You can use
547 # ActiveSupport::TimeZone.us_zones as a convenience for obtaining a list
548 # of the US time zones, or a Regexp to select the zones of your choice)
2bf29b3 @dhh Added FormOptionsHelper#time_zone_select and FormOptionsHelper#time_z…
dhh authored Feb 23, 2005
549 #
65d3430 @dhh Fixed TimeZone issues in action-pack and active-support #704
dhh authored Feb 23, 2005
550 # The +selected+ parameter must be either +nil+, or a string that names
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
551 # a ActiveSupport::TimeZone.
65d3430 @dhh Fixed TimeZone issues in action-pack and active-support #704
dhh authored Feb 23, 2005
552 #
e033b5d @lifo Merge docrails
lifo authored Jul 25, 2009
553 # By default, +model+ is the ActiveSupport::TimeZone constant (which can
554 # be obtained in Active Record as a value object). The only requirement
555 # is that the +model+ parameter be an object that responds to +all+, and
556 # returns an array of objects that represent time zones.
2bf29b3 @dhh Added FormOptionsHelper#time_zone_select and FormOptionsHelper#time_z…
dhh authored Feb 23, 2005
557 #
558 # NOTE: Only the option tags are returned, you have to wrap this call in
559 # a regular HTML select tag.
3f59429 @rubyruy TimeZone -> ActiveSupport::TimeZone. [#387 state:resolved]
rubyruy authored Jun 10, 2008
560 def time_zone_options_for_select(selected = nil, priority_zones = nil, model = ::ActiveSupport::TimeZone)
9dd64f2 @nashby refactor time_zone_options_for_select
nashby authored Feb 21, 2012
561 zone_options = "".html_safe
2bf29b3 @dhh Added FormOptionsHelper#time_zone_select and FormOptionsHelper#time_z…
dhh authored Feb 23, 2005
562
953e19e @carlosantoniodasilva Use Array Difference to calculate the zones array, instead of iterating
carlosantoniodasilva authored Feb 21, 2013
563 zones = model.all
65d3430 @dhh Fixed TimeZone issues in action-pack and active-support #704
dhh authored Feb 23, 2005
564 convert_zones = lambda { |list| list.map { |z| [ z.to_s, z.name ] } }
565
2bf29b3 @dhh Added FormOptionsHelper#time_zone_select and FormOptionsHelper#time_z…
dhh authored Feb 23, 2005
566 if priority_zones
2e487bc @rafaelfranca Whitespaces :scissors:
rafaelfranca authored Jan 5, 2012
567 if priority_zones.is_a?(Regexp)
1cc991b @bdmac Revert grep to select since they are not the same
bdmac authored Mar 27, 2013
568 priority_zones = zones.select { |z| z =~ priority_zones }
2e487bc @rafaelfranca Whitespaces :scissors:
rafaelfranca authored Jan 5, 2012
569 end
2bf29b3 @dhh Added FormOptionsHelper#time_zone_select and FormOptionsHelper#time_z…
dhh authored Feb 23, 2005
570
9dd64f2 @nashby refactor time_zone_options_for_select
nashby authored Feb 21, 2012
571 zone_options.safe_concat options_for_select(convert_zones[priority_zones], selected)
572 zone_options.safe_concat content_tag(:option, '-------------', :value => '', :disabled => 'disabled')
573 zone_options.safe_concat "\n"
574
953e19e @carlosantoniodasilva Use Array Difference to calculate the zones array, instead of iterating
carlosantoniodasilva authored Feb 21, 2013
575 zones = zones - priority_zones
2bf29b3 @dhh Added FormOptionsHelper#time_zone_select and FormOptionsHelper#time_z…
dhh authored Feb 23, 2005
576 end
577
9dd64f2 @nashby refactor time_zone_options_for_select
nashby authored Feb 21, 2012
578 zone_options.safe_concat options_for_select(convert_zones[zones], selected)
2bf29b3 @dhh Added FormOptionsHelper#time_zone_select and FormOptionsHelper#time_z…
dhh authored Feb 23, 2005
579 end
db045db @dhh Initial
dhh authored Nov 24, 2004
580
f506c80 @carlosantoniodasilva Add changelog, docs and guides entries
carlosantoniodasilva authored Feb 1, 2012
581 # Returns radio button tags for the collection of existing return values
582 # of +method+ for +object+'s class. The value returned from calling
583 # +method+ on the instance +object+ will be selected. If calling +method+
584 # returns +nil+, no selection is made.
585 #
586 # The <tt>:value_method</tt> and <tt>:text_method</tt> parameters are
587 # methods to be called on each member of +collection+. The return values
588 # are used as the +value+ attribute and contents of each radio button tag,
589 # respectively. They can also be any object that responds to +call+, such
590 # as a +proc+, that will be called for each member of the +collection+ to
591 # retrieve the value/text.
b161956 @carlosantoniodasilva Move collection radio buttons / check boxes back to FormOptionsHelper
carlosantoniodasilva authored Feb 1, 2012
592 #
593 # Example object structure for use with this method:
594 # class Post < ActiveRecord::Base
595 # belongs_to :author
596 # end
597 # class Author < ActiveRecord::Base
598 # has_many :posts
599 # def name_with_initial
600 # "#{first_name.first}. #{last_name}"
601 # end
602 # end
603 #
604 # Sample usage (selecting the associated Author for an instance of Post, <tt>@post</tt>):
605 # collection_radio_buttons(:post, :author_id, Author.all, :id, :name_with_initial)
606 #
607 # If <tt>@post.author_id</tt> is already <tt>1</tt>, this would return:
608 # <input id="post_author_id_1" name="post[author_id]" type="radio" value="1" checked="checked" />
5d8191a @rafaelfranca Remove default class to collection_check_boxes and
rafaelfranca authored Feb 1, 2012
609 # <label for="post_author_id_1">D. Heinemeier Hansson</label>
b161956 @carlosantoniodasilva Move collection radio buttons / check boxes back to FormOptionsHelper
carlosantoniodasilva authored Feb 1, 2012
610 # <input id="post_author_id_2" name="post[author_id]" type="radio" value="2" />
5d8191a @rafaelfranca Remove default class to collection_check_boxes and
rafaelfranca authored Feb 1, 2012
611 # <label for="post_author_id_2">D. Thomas</label>
b161956 @carlosantoniodasilva Move collection radio buttons / check boxes back to FormOptionsHelper
carlosantoniodasilva authored Feb 1, 2012
612 # <input id="post_author_id_3" name="post[author_id]" type="radio" value="3" />
5d8191a @rafaelfranca Remove default class to collection_check_boxes and
rafaelfranca authored Feb 1, 2012
613 # <label for="post_author_id_3">M. Clark</label>
f506c80 @carlosantoniodasilva Add changelog, docs and guides entries
carlosantoniodasilva authored Feb 1, 2012
614 #
615 # It is also possible to customize the way the elements will be shown by
616 # giving a block to the method:
617 # collection_radio_buttons(:post, :author_id, Author.all, :id, :name_with_initial) do |b|
618 # b.label { b.radio_button }
619 # end
620 #
621 # The argument passed to the block is a special kind of builder for this
622 # collection, which has the ability to generate the label and radio button
623 # for the current item in the collection, with proper text and value.
624 # Using it, you can change the label and radio button display order or
625 # even use the label as wrapper, as in the example above.
626 #
627 # The builder methods <tt>label</tt> and <tt>radio_button</tt> also accept
628 # extra html options:
5d8191a @rafaelfranca Remove default class to collection_check_boxes and
rafaelfranca authored Feb 1, 2012
629 # collection_radio_buttons(:post, :author_id, Author.all, :id, :name_with_initial) do |b|
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
630 # b.label(class: "radio_button") { b.radio_button(class: "radio_button") }
f506c80 @carlosantoniodasilva Add changelog, docs and guides entries
carlosantoniodasilva authored Feb 1, 2012
631 # end
0f23426 @carlosantoniodasilva Allow collection radio_buttons/check_boxes to access current text/value
carlosantoniodasilva authored Feb 1, 2012
632 #
80680e9 @rafaelfranca Add documentation to object method of CollectionHelpers::Builder
rafaelfranca authored Feb 26, 2012
633 # There are also three special methods available: <tt>object</tt>, <tt>text</tt> and
634 # <tt>value</tt>, which are the current item being rendered, its text and value methods,
635 # respectively. You can use them like this:
5d8191a @rafaelfranca Remove default class to collection_check_boxes and
rafaelfranca authored Feb 1, 2012
636 # collection_radio_buttons(:post, :author_id, Author.all, :id, :name_with_initial) do |b|
0f23426 @carlosantoniodasilva Allow collection radio_buttons/check_boxes to access current text/value
carlosantoniodasilva authored Feb 1, 2012
637 # b.label(:"data-value" => b.value) { b.radio_button + b.text }
638 # end
b161956 @carlosantoniodasilva Move collection radio buttons / check boxes back to FormOptionsHelper
carlosantoniodasilva authored Feb 1, 2012
639 def collection_radio_buttons(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
640 Tags::CollectionRadioButtons.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block)
641 end
642
f506c80 @carlosantoniodasilva Add changelog, docs and guides entries
carlosantoniodasilva authored Feb 1, 2012
643 # Returns check box tags for the collection of existing return values of
644 # +method+ for +object+'s class. The value returned from calling +method+
645 # on the instance +object+ will be selected. If calling +method+ returns
646 # +nil+, no selection is made.
647 #
648 # The <tt>:value_method</tt> and <tt>:text_method</tt> parameters are
649 # methods to be called on each member of +collection+. The return values
650 # are used as the +value+ attribute and contents of each check box tag,
651 # respectively. They can also be any object that responds to +call+, such
652 # as a +proc+, that will be called for each member of the +collection+ to
653 # retrieve the value/text.
b161956 @carlosantoniodasilva Move collection radio buttons / check boxes back to FormOptionsHelper
carlosantoniodasilva authored Feb 1, 2012
654 #
655 # Example object structure for use with this method:
656 # class Post < ActiveRecord::Base
f506c80 @carlosantoniodasilva Add changelog, docs and guides entries
carlosantoniodasilva authored Feb 1, 2012
657 # has_and_belongs_to_many :author
b161956 @carlosantoniodasilva Move collection radio buttons / check boxes back to FormOptionsHelper
carlosantoniodasilva authored Feb 1, 2012
658 # end
659 # class Author < ActiveRecord::Base
f506c80 @carlosantoniodasilva Add changelog, docs and guides entries
carlosantoniodasilva authored Feb 1, 2012
660 # has_and_belongs_to_many :posts
b161956 @carlosantoniodasilva Move collection radio buttons / check boxes back to FormOptionsHelper
carlosantoniodasilva authored Feb 1, 2012
661 # def name_with_initial
662 # "#{first_name.first}. #{last_name}"
663 # end
664 # end
665 #
666 # Sample usage (selecting the associated Author for an instance of Post, <tt>@post</tt>):
667 # collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial)
668 #
669 # If <tt>@post.author_ids</tt> is already <tt>[1]</tt>, this would return:
670 # <input id="post_author_ids_1" name="post[author_ids][]" type="checkbox" value="1" checked="checked" />
5d8191a @rafaelfranca Remove default class to collection_check_boxes and
rafaelfranca authored Feb 1, 2012
671 # <label for="post_author_ids_1">D. Heinemeier Hansson</label>
f506c80 @carlosantoniodasilva Add changelog, docs and guides entries
carlosantoniodasilva authored Feb 1, 2012
672 # <input id="post_author_ids_2" name="post[author_ids][]" type="checkbox" value="2" />
5d8191a @rafaelfranca Remove default class to collection_check_boxes and
rafaelfranca authored Feb 1, 2012
673 # <label for="post_author_ids_2">D. Thomas</label>
b161956 @carlosantoniodasilva Move collection radio buttons / check boxes back to FormOptionsHelper
carlosantoniodasilva authored Feb 1, 2012
674 # <input id="post_author_ids_3" name="post[author_ids][]" type="checkbox" value="3" />
5d8191a @rafaelfranca Remove default class to collection_check_boxes and
rafaelfranca authored Feb 1, 2012
675 # <label for="post_author_ids_3">M. Clark</label>
b161956 @carlosantoniodasilva Move collection radio buttons / check boxes back to FormOptionsHelper
carlosantoniodasilva authored Feb 1, 2012
676 # <input name="post[author_ids][]" type="hidden" value="" />
f506c80 @carlosantoniodasilva Add changelog, docs and guides entries
carlosantoniodasilva authored Feb 1, 2012
677 #
678 # It is also possible to customize the way the elements will be shown by
679 # giving a block to the method:
680 # collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
681 # b.label { b.check_box }
682 # end
683 #
684 # The argument passed to the block is a special kind of builder for this
685 # collection, which has the ability to generate the label and check box
686 # for the current item in the collection, with proper text and value.
687 # Using it, you can change the label and check box display order or even
688 # use the label as wrapper, as in the example above.
689 #
690 # The builder methods <tt>label</tt> and <tt>check_box</tt> also accept
691 # extra html options:
692 # collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
be4a4cd @AvnerCohen Hash Syntax to 1.9 related changes
AvnerCohen authored Oct 29, 2012
693 # b.label(class: "check_box") { b.check_box(class: "check_box") }
f506c80 @carlosantoniodasilva Add changelog, docs and guides entries
carlosantoniodasilva authored Feb 1, 2012
694 # end
0f23426 @carlosantoniodasilva Allow collection radio_buttons/check_boxes to access current text/value
carlosantoniodasilva authored Feb 1, 2012
695 #
80680e9 @rafaelfranca Add documentation to object method of CollectionHelpers::Builder
rafaelfranca authored Feb 26, 2012
696 # There are also three special methods available: <tt>object</tt>, <tt>text</tt> and
697 # <tt>value</tt>, which are the current item being rendered, its text and value methods,
698 # respectively. You can use them like this:
0f23426 @carlosantoniodasilva Allow collection radio_buttons/check_boxes to access current text/value
carlosantoniodasilva authored Feb 1, 2012
699 # collection_check_boxes(:post, :author_ids, Author.all, :id, :name_with_initial) do |b|
700 # b.label(:"data-value" => b.value) { b.check_box + b.text }
701 # end
b161956 @carlosantoniodasilva Move collection radio buttons / check boxes back to FormOptionsHelper
carlosantoniodasilva authored Feb 1, 2012
702 def collection_check_boxes(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
703 Tags::CollectionCheckBoxes.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block)
704 end
705
db045db @dhh Initial
dhh authored Nov 24, 2004
706 private
2dc1402 @pleax added support for html attributes in options_for_select [#2165]
pleax authored May 15, 2010
707 def option_html_attributes(element)
e8e8617 @carlosantoniodasilva Simplify html attributes generation for options_for_select
carlosantoniodasilva authored Aug 11, 2012
708 if Array === element
a513cc1 @carlosantoniodasilva Ensure option_html_attributes does not modify the given option hashes
carlosantoniodasilva authored Aug 11, 2012
709 element.select { |e| Hash === e }.reduce({}, :merge!)
e8e8617 @carlosantoniodasilva Simplify html attributes generation for options_for_select
carlosantoniodasilva authored Aug 11, 2012
710 else
711 {}
712 end
2dc1402 @pleax added support for html attributes in options_for_select [#2165]
pleax authored May 15, 2010
713 end
714
3edc98a @jeremy form_options_helper refactoring for clarity. Closes #7787.
jeremy authored Mar 11, 2007
715 def option_text_and_value(option)
716 # Options are [text, value] pairs or strings used for both.
50cf5f7 @nashby refactor option_text_and_value and option_value_selected? methods
nashby authored Feb 21, 2012
717 if !option.is_a?(String) && option.respond_to?(:first) && option.respond_to?(:last)
718 option = option.reject { |e| Hash === e } if Array === option
3edc98a @jeremy form_options_helper refactoring for clarity. Closes #7787.
jeremy authored Mar 11, 2007
719 [option.first, option.last]
720 else
721 [option, option]
722 end
723 end
724
725 def option_value_selected?(value, selected)
50cf5f7 @nashby refactor option_text_and_value and option_value_selected? methods
nashby authored Feb 21, 2012
726 Array(selected).include? value
3edc98a @jeremy form_options_helper refactoring for clarity. Closes #7787.
jeremy authored Mar 11, 2007
727 end
1525f38 @tekin Enhanced form option helpers to add support for disabled option tags …
tekin authored Feb 14, 2009
728
729 def extract_selected_and_disabled(selected)
54477c9 @subbarao select tags coerce the :selected option, options to strings before co…
subbarao authored Aug 14, 2010
730 if selected.is_a?(Proc)
4a18cbb @carlosantoniodasilva Cleanup options helper methods a bit
carlosantoniodasilva authored Jan 31, 2012
731 [selected, nil]
1525f38 @tekin Enhanced form option helpers to add support for disabled option tags …
tekin authored Feb 14, 2009
732 else
54477c9 @subbarao select tags coerce the :selected option, options to strings before co…
subbarao authored Aug 14, 2010
733 selected = Array.wrap(selected)
9035324 @carlosantoniodasilva Allow proc for value/text method in collection_select
carlosantoniodasilva authored Feb 1, 2012
734 options = selected.extract_options!.symbolize_keys
4a18cbb @carlosantoniodasilva Cleanup options helper methods a bit
carlosantoniodasilva authored Jan 31, 2012
735 selected_items = options.fetch(:selected, selected)
736 [selected_items, options[:disabled]]
1525f38 @tekin Enhanced form option helpers to add support for disabled option tags …
tekin authored Feb 14, 2009
737 end
738 end
739
740 def extract_values_from_collection(collection, value_method, selected)
741 if selected.is_a?(Proc)
742 collection.map do |element|
743 element.send(value_method) if selected.call(element)
744 end.compact
745 else
746 selected
747 end
748 end
9035324 @carlosantoniodasilva Allow proc for value/text method in collection_select
carlosantoniodasilva authored Feb 1, 2012
749
750 def value_for_collection(item, value)
751 value.respond_to?(:call) ? value.call(item) : item.send(value)
752 end
982ed06 @rafaelfranca Make :prompt work as documented
rafaelfranca authored May 16, 2012
753
754 def prompt_text(prompt)
f23e7eb @vipulnsward remove unused variable and assignment
vipulnsward authored Mar 31, 2013
755 prompt.kind_of?(String) ? prompt : I18n.translate('helpers.select.prompt', :default => 'Please select')
982ed06 @rafaelfranca Make :prompt work as documented
rafaelfranca authored May 16, 2012
756 end
db045db @dhh Initial
dhh authored Nov 24, 2004
757 end
758
947cec2 @dhh Added FormHelper#form_for and FormHelper#fields_for that makes it eas…
dhh authored Nov 13, 2005
759 class FormBuilder
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
760 # Wraps ActionView::Helpers::FormOptionsHelper#select for form builders:
8c60391 @thejamespinto repeating documentation for option form helpers
thejamespinto authored Jan 17, 2013
761 #
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
762 # <%= form_for @post do |f| %>
763 # <%= f.select :person_id, Person.all.collect {|p| [ p.name, p.id ] }, { include_blank: true }) %>
764 # <%= f.submit %>
765 # <% end %>
8c60391 @thejamespinto repeating documentation for option form helpers
thejamespinto authored Jan 17, 2013
766 #
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
767 # Please refer to the documentation of the base helper for details.
947cec2 @dhh Added FormHelper#form_for and FormHelper#fields_for that makes it eas…
dhh authored Nov 13, 2005
768 def select(method, choices, options = {}, html_options = {})
95812d5 Ensure :index works with fields_for select methods. [#518 state:resol…
rsl authored Jul 14, 2008
769 @template.select(@object_name, method, choices, objectify_options(options), @default_options.merge(html_options))
947cec2 @dhh Added FormHelper#form_for and FormHelper#fields_for that makes it eas…
dhh authored Nov 13, 2005
770 end
771
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
772 # Wraps ActionView::Helpers::FormOptionsHelper#collection_select for form builders:
8c60391 @thejamespinto repeating documentation for option form helpers
thejamespinto authored Jan 17, 2013
773 #
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
774 # <%= form_for @post do |f| %>
775 # <%= f.collection_select :person_id, Author.all, :id, :name_with_initial, prompt: true %>
776 # <%= f.submit %>
777 # <% end %>
8c60391 @thejamespinto repeating documentation for option form helpers
thejamespinto authored Jan 17, 2013
778 #
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
779 # Please refer to the documentation of the base helper for details.
947cec2 @dhh Added FormHelper#form_for and FormHelper#fields_for that makes it eas…
dhh authored Nov 13, 2005
780 def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
95812d5 Ensure :index works with fields_for select methods. [#518 state:resol…
rsl authored Jul 13, 2008
781 @template.collection_select(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options))
947cec2 @dhh Added FormHelper#form_for and FormHelper#fields_for that makes it eas…
dhh authored Nov 13, 2005
782 end
783
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
784 # Wraps ActionView::Helpers::FormOptionsHelper#grouped_collection_select for form builders:
8c60391 @thejamespinto repeating documentation for option form helpers
thejamespinto authored Jan 17, 2013
785 #
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
786 # <%= form_for @city do |f| %>
787 # <%= f.grouped_collection_select :country_id, :country_id, @continents, :countries, :name, :id, :name %>
788 # <%= f.submit %>
789 # <% end %>
8c60391 @thejamespinto repeating documentation for option form helpers
thejamespinto authored Jan 17, 2013
790 #
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
791 # Please refer to the documentation of the base helper for details.
8c32248 Introduce grouped_collection_select helper.
codeape authored Aug 10, 2009
792 def grouped_collection_select(method, collection, group_method, group_label_method, option_key_method, option_value_method, options = {}, html_options = {})
793 @template.grouped_collection_select(@object_name, method, collection, group_method, group_label_method, option_key_method, option_value_method, objectify_options(options), @default_options.merge(html_options))
794 end
795
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
796 # Wraps ActionView::Helpers::FormOptionsHelper#time_zone_select for form builders:
8c60391 @thejamespinto repeating documentation for option form helpers
thejamespinto authored Jan 17, 2013
797 #
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
798 # <%= form_for @user do |f| %>
799 # <%= f.time_zone_select :time_zone, nil, include_blank: true %>
800 # <%= f.submit %>
801 # <% end %>
8c60391 @thejamespinto repeating documentation for option form helpers
thejamespinto authored Jan 17, 2013
802 #
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
803 # Please refer to the documentation of the base helper for details.
947cec2 @dhh Added FormHelper#form_for and FormHelper#fields_for that makes it eas…
dhh authored Nov 13, 2005
804 def time_zone_select(method, priority_zones = nil, options = {}, html_options = {})
95812d5 Ensure :index works with fields_for select methods. [#518 state:resol…
rsl authored Jul 13, 2008
805 @template.time_zone_select(@object_name, method, priority_zones, objectify_options(options), @default_options.merge(html_options))
947cec2 @dhh Added FormHelper#form_for and FormHelper#fields_for that makes it eas…
dhh authored Nov 13, 2005
806 end
b161956 @carlosantoniodasilva Move collection radio buttons / check boxes back to FormOptionsHelper
carlosantoniodasilva authored Feb 1, 2012
807
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
808 # Wraps ActionView::Helpers::FormOptionsHelper#collection_check_boxes for form builders:
8c60391 @thejamespinto repeating documentation for option form helpers
thejamespinto authored Jan 17, 2013
809 #
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
810 # <%= form_for @post do |f| %>
811 # <%= f.collection_check_boxes :author_ids, Author.all, :id, :name_with_initial %>
812 # <%= f.submit %>
813 # <% end %>
8c60391 @thejamespinto repeating documentation for option form helpers
thejamespinto authored Jan 17, 2013
814 #
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
815 # Please refer to the documentation of the base helper for details.
8cc60d8 @josemotanet Collection radio buttons and collection check boxes through FormBuild…
josemotanet authored Jan 12, 2013
816 def collection_check_boxes(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
817 @template.collection_check_boxes(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options), &block)
b161956 @carlosantoniodasilva Move collection radio buttons / check boxes back to FormOptionsHelper
carlosantoniodasilva authored Feb 1, 2012
818 end
819
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
820 # Wraps ActionView::Helpers::FormOptionsHelper#collection_radio_buttons for form builders:
8c60391 @thejamespinto repeating documentation for option form helpers
thejamespinto authored Jan 17, 2013
821 #
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
822 # <%= form_for @post do |f| %>
823 # <%= f.collection_radio_buttons :author_id, Author.all, :id, :name_with_initial %>
824 # <%= f.submit %>
825 # <% end %>
8c60391 @thejamespinto repeating documentation for option form helpers
thejamespinto authored Jan 17, 2013
826 #
4313461 @fxn generic pass before merging docrails
fxn authored Jan 26, 2013
827 # Please refer to the documentation of the base helper for details.
8cc60d8 @josemotanet Collection radio buttons and collection check boxes through FormBuild…
josemotanet authored Jan 12, 2013
828 def collection_radio_buttons(method, collection, value_method, text_method, options = {}, html_options = {}, &block)
829 @template.collection_radio_buttons(@object_name, method, collection, value_method, text_method, objectify_options(options), @default_options.merge(html_options), &block)
b161956 @carlosantoniodasilva Move collection radio buttons / check boxes back to FormOptionsHelper
carlosantoniodasilva authored Feb 1, 2012
830 end
947cec2 @dhh Added FormHelper#form_for and FormHelper#fields_for that makes it eas…
dhh authored Nov 13, 2005
831 end
db045db @dhh Initial
dhh authored Nov 24, 2004
832 end
65d3430 @dhh Fixed TimeZone issues in action-pack and active-support #704
dhh authored Feb 23, 2005
833 end
Something went wrong with that request. Please try again.