提交 6c0d5a19 编写于 作者: J José Valim

Merge pull request #5366 from parndt/fix_issue_5324

Fixes #5324 by removing default size options from input:text and default cols and rows options from textarea.
## Rails 4.0.0 (unreleased) ##
* Removed default `size` option from the `text_field`, `search_field`, `telephone_field`, `url_field`, `email_field` helpers. *Philip Arndt*
* Removed default `cols` and `rows` options from the `text_area` helper. *Philip Arndt*
* Adds support for layouts when rendering a partial with a given collection. *serabe*
* Allows the route helper `root` to take a string argument. For example, `root 'pages#main'`. *bcardarella*
......
......@@ -45,10 +45,10 @@ module Helpers
# <input name="authenticity_token" type="hidden" value="NrOp5bsjoLRuK8IW5+dQEYjKGUJDe7TQoZVvq95Wteg=" />
# </div>
# <label for="person_first_name">First name</label>:
# <input id="person_first_name" name="person[first_name]" size="30" type="text" /><br />
# <input id="person_first_name" name="person[first_name]" type="text" /><br />
#
# <label for="person_last_name">Last name</label>:
# <input id="person_last_name" name="person[last_name]" size="30" type="text" /><br />
# <input id="person_last_name" name="person[last_name]" type="text" /><br />
#
# <input name="commit" type="submit" value="Create Person" />
# </form>
......@@ -76,10 +76,10 @@ module Helpers
# <input name="authenticity_token" type="hidden" value="NrOp5bsjoLRuK8IW5+dQEYjKGUJDe7TQoZVvq95Wteg=" />
# </div>
# <label for="person_first_name">First name</label>:
# <input id="person_first_name" name="person[first_name]" size="30" type="text" value="John" /><br />
# <input id="person_first_name" name="person[first_name]" type="text" value="John" /><br />
#
# <label for="person_last_name">Last name</label>:
# <input id="person_last_name" name="person[last_name]" size="30" type="text" value="Smith" /><br />
# <input id="person_last_name" name="person[last_name]" type="text" value="Smith" /><br />
#
# <input name="commit" type="submit" value="Update Person" />
# </form>
......@@ -860,20 +860,20 @@ def radio_button(object_name, method, tag_value, options = {})
# ==== Examples
#
# search_field(:user, :name)
# # => <input id="user_name" name="user[name]" size="30" type="search" />
# # => <input id="user_name" name="user[name]" type="search" />
# search_field(:user, :name, :autosave => false)
# # => <input autosave="false" id="user_name" name="user[name]" size="30" type="search" />
# # => <input autosave="false" id="user_name" name="user[name]" type="search" />
# search_field(:user, :name, :results => 3)
# # => <input id="user_name" name="user[name]" results="3" size="30" type="search" />
# # => <input id="user_name" name="user[name]" results="3" type="search" />
# # Assume request.host returns "www.example.com"
# search_field(:user, :name, :autosave => true)
# # => <input autosave="com.example.www" id="user_name" name="user[name]" results="10" size="30" type="search" />
# # => <input autosave="com.example.www" id="user_name" name="user[name]" results="10" type="search" />
# search_field(:user, :name, :onsearch => true)
# # => <input id="user_name" incremental="true" name="user[name]" onsearch="true" size="30" type="search" />
# # => <input id="user_name" incremental="true" name="user[name]" onsearch="true" type="search" />
# search_field(:user, :name, :autosave => false, :onsearch => true)
# # => <input autosave="false" id="user_name" incremental="true" name="user[name]" onsearch="true" size="30" type="search" />
# # => <input autosave="false" id="user_name" incremental="true" name="user[name]" onsearch="true" type="search" />
# search_field(:user, :name, :autosave => true, :onsearch => true)
# # => <input autosave="com.example.www" id="user_name" incremental="true" name="user[name]" onsearch="true" results="10" size="30" type="search" />
# # => <input autosave="com.example.www" id="user_name" incremental="true" name="user[name]" onsearch="true" results="10" type="search" />
#
def search_field(object_name, method, options = {})
Tags::SearchField.new(object_name, method, self, options).render
......@@ -882,7 +882,7 @@ def search_field(object_name, method, options = {})
# Returns a text_field of type "tel".
#
# telephone_field("user", "phone")
# # => <input id="user_phone" name="user[phone]" size="30" type="tel" />
# # => <input id="user_phone" name="user[phone]" type="tel" />
#
def telephone_field(object_name, method, options = {})
Tags::TelField.new(object_name, method, self, options).render
......@@ -910,7 +910,7 @@ def date_field(object_name, method, options = {})
# Returns a text_field of type "url".
#
# url_field("user", "homepage")
# # => <input id="user_homepage" size="30" name="user[homepage]" type="url" />
# # => <input id="user_homepage" name="user[homepage]" type="url" />
#
def url_field(object_name, method, options = {})
Tags::UrlField.new(object_name, method, self, options).render
......@@ -919,7 +919,7 @@ def url_field(object_name, method, options = {})
# Returns a text_field of type "email".
#
# email_field("user", "address")
# # => <input id="user_address" size="30" name="user[address]" type="email" />
# # => <input id="user_address" name="user[address]" type="email" />
#
def email_field(object_name, method, options = {})
Tags::EmailField.new(object_name, method, self, options).render
......
......@@ -5,8 +5,6 @@ class Base #:nodoc:
include Helpers::ActiveModelInstanceTag, Helpers::TagHelper, Helpers::FormTagHelper
include FormOptionsHelper
DEFAULT_FIELD_OPTIONS = { "size" => 30 }
attr_reader :object
def initialize(object_name, method_name, template_object, options = {})
......
......@@ -2,10 +2,8 @@ module ActionView
module Helpers
module Tags
class TextArea < Base #:nodoc:
DEFAULT_TEXT_AREA_OPTIONS = { "cols" => 40, "rows" => 20 }
def render
options = DEFAULT_TEXT_AREA_OPTIONS.merge(@options.stringify_keys)
options = @options.stringify_keys
add_default_name_and_id(options)
if size = options.delete("size")
......
......@@ -4,8 +4,7 @@ module Tags
class TextField < Base #:nodoc:
def render
options = @options.stringify_keys
options["size"] = options["maxlength"] || DEFAULT_FIELD_OPTIONS["size"] unless options.key?("size")
options = DEFAULT_FIELD_OPTIONS.merge(options)
options["size"] = options["maxlength"] unless options.key?("size")
options["type"] ||= field_type
options["value"] = options.fetch("value"){ value_before_type_cast(object) } unless field_type == "file"
options["value"] &&= ERB::Util.html_escape(options["value"])
......
......@@ -29,14 +29,14 @@ def setup
def test_text_area_with_errors
assert_dom_equal(
%(<div class="field_with_errors"><textarea cols="40" id="post_body" name="post[body]" rows="20">\nBack to the hill and over it again!</textarea></div>),
%(<div class="field_with_errors"><textarea id="post_body" name="post[body]">\nBack to the hill and over it again!</textarea></div>),
text_area("post", "body")
)
end
def test_text_field_with_errors
assert_dom_equal(
%(<div class="field_with_errors"><input id="post_author_name" name="post[author_name]" size="30" type="text" value="" /></div>),
%(<div class="field_with_errors"><input id="post_author_name" name="post[author_name]" type="text" value="" /></div>),
text_field("post", "author_name")
)
end
......@@ -76,7 +76,7 @@ def test_field_error_proc
end
assert_dom_equal(
%(<div class="field_with_errors"><input id="post_author_name" name="post[author_name]" size="30" type="text" value="" /> <span class="error">can't be empty</span></div>),
%(<div class="field_with_errors"><input id="post_author_name" name="post[author_name]" type="text" value="" /> <span class="error">can't be empty</span></div>),
text_field("post", "author_name")
)
ensure
......
......@@ -431,11 +431,11 @@ form("post")
<form action='/posts/create' method='post'>
<p>
<label for="post_title">Title</label><br />
<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />
<input id="post_title" name="post[title]" type="text" value="Hello World" />
</p>
<p>
<label for="post_body">Body</label><br />
<textarea cols="40" id="post_body" name="post[body]" rows="20"></textarea>
<textarea id="post_body" name="post[body]"></textarea>
</p>
<input name="commit" type="submit" value="Create" />
</form>
......@@ -451,7 +451,7 @@ For example, if +@post+ has an attribute +title+ mapped to a +String+ column tha
<ruby>
input("post", "title") # =>
<input id="post_title" name="post[title]" size="30" type="text" value="Hello World" />
<input id="post_title" name="post[title]" type="text" value="Hello World" />
</ruby>
h4. RecordTagHelper
......@@ -987,8 +987,8 @@ The HTML generated for this would be:
<html>
<form action="/persons/create" method="post">
<input id="person_first_name" name="person[first_name]" size="30" type="text" />
<input id="person_last_name" name="person[last_name]" size="30" type="text" />
<input id="person_first_name" name="person[first_name]" type="text" />
<input id="person_last_name" name="person[last_name]" type="text" />
<input name="commit" type="submit" value="Create" />
</form>
</html>
......
......@@ -169,11 +169,11 @@ Output:
<textarea id="message" name="message" cols="24" rows="6">Hi, nice site</textarea>
<input id="password" name="password" type="password" />
<input id="parent_id" name="parent_id" type="hidden" value="5" />
<input id="user_name" name="user[name]" size="30" type="search" />
<input id="user_phone" name="user[phone]" size="30" type="tel" />
<input id="user_name" name="user[name]" type="search" />
<input id="user_phone" name="user[phone]" type="tel" />
<input id="user_born_on" name="user[born_on]" type="date" />
<input id="user_homepage" size="30" name="user[homepage]" type="url" />
<input id="user_address" size="30" name="user[address]" type="email" />
<input id="user_homepage" name="user[homepage]" type="url" />
<input id="user_address" name="user[address]" type="email" />
</html>
Hidden inputs are not shown to the user but instead hold data like any textual input. Values inside them can be changed with JavaScript.
......@@ -239,7 +239,7 @@ The resulting HTML is:
<html>
<form accept-charset="UTF-8" action="/articles/create" method="post" class="nifty_form">
<input id="article_title" name="article[title]" size="30" type="text" />
<input id="article_title" name="article[title]" type="text" />
<textarea id="article_body" name="article[body]" cols="60" rows="12"></textarea>
<input name="commit" type="submit" value="Create" />
</form>
......@@ -264,8 +264,8 @@ which produces the following output:
<html>
<form accept-charset="UTF-8" action="/people/create" class="new_person" id="new_person" method="post">
<input id="person_name" name="person[name]" size="30" type="text" />
<input id="contact_detail_phone_number" name="contact_detail[phone_number]" size="30" type="text" />
<input id="person_name" name="person[name]" type="text" />
<input id="contact_detail_phone_number" name="contact_detail[phone_number]" type="text" />
</form>
</html>
......@@ -714,9 +714,9 @@ Assuming the person had two addresses, with ids 23 and 45 this would create outp
<html>
<form accept-charset="UTF-8" action="/people/1" class="edit_person" id="edit_person_1" method="post">
<input id="person_name" name="person[name]" size="30" type="text" />
<input id="person_address_23_city" name="person[address][23][city]" size="30" type="text" />
<input id="person_address_45_city" name="person[address][45][city]" size="30" type="text" />
<input id="person_name" name="person[name]" type="text" />
<input id="person_address_23_city" name="person[address][23][city]" type="text" />
<input id="person_address_45_city" name="person[address][45][city]" type="text" />
</form>
</html>
......@@ -739,7 +739,7 @@ To create more intricate nestings, you can specify the first part of the input n
will create inputs like
<html>
<input id="person_address_primary_1_city" name="person[address][primary][1][city]" size="30" type="text" value="bologna" />
<input id="person_address_primary_1_city" name="person[address][primary][1][city]" type="text" value="bologna" />
</html>
As a general rule the final input name is the concatenation of the name given to +fields_for+/+form_for+, the index value and the name of the attribute. You can also pass an +:index+ option directly to helpers such as +text_field+, but it is usually less repetitive to specify this at the form builder level rather than on individual input controls.
......
......@@ -131,7 +131,7 @@ This will generate the following html:
<html>
<form action="/people" class="new_person" id="new_person" method="post">
<input id="person_name" name="person[name]" size="30" type="text" />
<input id="person_name" name="person[name]" type="text" />
</form>
</html>
......@@ -153,9 +153,9 @@ This generates:
<html>
<form action="/people" class="new_person" id="new_person" method="post">
<input id="person_name" name="person[name]" size="30" type="text" />
<input id="person_name" name="person[name]" type="text" />
<input id="person_address_attributes_street" name="person[address_attributes][street]" size="30" type="text" />
<input id="person_address_attributes_street" name="person[address_attributes][street]" type="text" />
</form>
</html>
......@@ -194,10 +194,10 @@ Which generates:
<html>
<form action="/people" class="new_person" id="new_person" method="post">
<input id="person_name" name="person[name]" size="30" type="text" />
<input id="person_name" name="person[name]" type="text" />
<input id="person_projects_attributes_0_name" name="person[projects_attributes][0][name]" size="30" type="text" />
<input id="person_projects_attributes_1_name" name="person[projects_attributes][1][name]" size="30" type="text" />
<input id="person_projects_attributes_0_name" name="person[projects_attributes][0][name]" type="text" />
<input id="person_projects_attributes_1_name" name="person[projects_attributes][1][name]" type="text" />
</form>
</html>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册