Added that form helpers now take an index option #448 [Tim Bates]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@378 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
445f89ccb5
commit
2594f2abe9
|
@ -1,5 +1,13 @@
|
||||||
*SVN*
|
*SVN*
|
||||||
|
|
||||||
|
* Added that form helpers now take an index option #448 [Tim Bates]
|
||||||
|
|
||||||
|
Example:
|
||||||
|
text_field "person", "name", "index" => 3
|
||||||
|
|
||||||
|
Becomes:
|
||||||
|
<input type="text" name="person[3][name]" id="person_3_name" value="<%= @person.name %>" />
|
||||||
|
|
||||||
* Fixed three issues with retrying breakpoints #417 [Florian Gross]
|
* Fixed three issues with retrying breakpoints #417 [Florian Gross]
|
||||||
|
|
||||||
1. Don't screw up pages that use multiple values for the same parameter (?foo=bar&foo=qux was converted to ?foo=barqux)
|
1. Don't screw up pages that use multiple values for the same parameter (?foo=bar&foo=qux was converted to ?foo=barqux)
|
||||||
|
|
|
@ -45,6 +45,15 @@ module ActionView
|
||||||
# <input type="submit" value="Save">
|
# <input type="submit" value="Save">
|
||||||
# </form>
|
# </form>
|
||||||
#
|
#
|
||||||
|
# If the helper is being used to generate a repetitive sequence of similar form elements, for example in a partial
|
||||||
|
# used by render_collection_of_partials, the "index" option may come in handy. Example:
|
||||||
|
#
|
||||||
|
# <%= text_field "person", "name", "index" => 1 %>
|
||||||
|
#
|
||||||
|
# becomes
|
||||||
|
#
|
||||||
|
# <input type="text" id="person_1_name" name="person[1][name]" value="<%= @person.name %>" />
|
||||||
|
#
|
||||||
# There's also methods for helping to build form tags in link:classes/ActionView/Helpers/FormOptionsHelper.html,
|
# There's also methods for helping to build form tags in link:classes/ActionView/Helpers/FormOptionsHelper.html,
|
||||||
# link:classes/ActionView/Helpers/DateHelper.html, and link:classes/ActionView/Helpers/ActiveRecordHelper.html
|
# link:classes/ActionView/Helpers/DateHelper.html, and link:classes/ActionView/Helpers/ActiveRecordHelper.html
|
||||||
module FormHelper
|
module FormHelper
|
||||||
|
@ -201,17 +210,31 @@ module ActionView
|
||||||
|
|
||||||
private
|
private
|
||||||
def add_default_name_and_id(options)
|
def add_default_name_and_id(options)
|
||||||
|
if options.has_key? "index"
|
||||||
|
options['name'] = tag_name_with_index(options["index"]) unless options.has_key? "name"
|
||||||
|
options['id'] = tag_id_with_index(options["index"]) unless options.has_key? "id"
|
||||||
|
options.delete("index")
|
||||||
|
else
|
||||||
options['name'] = tag_name unless options.has_key? "name"
|
options['name'] = tag_name unless options.has_key? "name"
|
||||||
options['id'] = tag_id unless options.has_key? "id"
|
options['id'] = tag_id unless options.has_key? "id"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def tag_name
|
def tag_name
|
||||||
"#{@object_name}[#{@method_name}]"
|
"#{@object_name}[#{@method_name}]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tag_name_with_index(index)
|
||||||
|
"#{@object_name}[#{index}][#{@method_name}]"
|
||||||
|
end
|
||||||
|
|
||||||
def tag_id
|
def tag_id
|
||||||
"#{@object_name}_#{@method_name}"
|
"#{@object_name}_#{@method_name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tag_id_with_index(index)
|
||||||
|
"#{@object_name}_#{index}_#{@method_name}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue