Permalink
Browse files

Add default input size.

  • Loading branch information...
1 parent d8b97c7 commit 086b20a7a52b562f6403a284caea8fead5d112e7 @josevalim josevalim committed Feb 6, 2010
@@ -35,4 +35,7 @@
# Default priority for country inputs.
# config.country_priority = nil
+
+ # Default size for text inputs
+ # config.default_input_size = 50
end
View
@@ -49,6 +49,10 @@ module SimpleForm
mattr_accessor :country_priority
@@country_priority = nil
+ # Maximum size allowed for inputs.
+ mattr_accessor :default_input_size
+ @@default_input_size = 50
+
# Default way to setup SimpleForm. Run script/generate simple_form_install
# to create a fresh initializer with all configuration values.
def self.setup
@@ -8,9 +8,20 @@ def input
def input_html_options
input_options = super
- input_options[:maxlength] ||= column.limit if column
+ if text_type? && column && column.limit
+ input_options[:size] ||= [column.limit, SimpleForm.default_input_size].min
+ input_options[:maxlength] ||= column.limit
+ else
+ input_options[:size] ||= SimpleForm.default_input_size
+ end
input_options
end
+
+ protected
+
+ def text_type?
+ [:string, :email, :url].include?(input_type)
+ end
end
end
end
@@ -1,8 +1,8 @@
<%% simple_form_for(@<%= singular_name %>) do |f| %>
<div class="inputs">
- <% attibutes.each do |attribute| %>
+ <%- attributes.each do |attribute| -%>
<%%= f.<%= attribute.reference? ? :association : :input %> :<%= attribute.name %> %>
- <% end -%>
+ <%- end -%>
</div>
<div class="actions">
View
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{simple_form}
- s.version = "1.0.0"
+ s.version = "1.1.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Jos\303\251 Valim", "Carlos Ant\303\264nio"]
@@ -16,14 +16,13 @@ Gem::Specification.new do |s|
"README.rdoc"
]
s.files = [
- "generators/simple_form_install/USAGE",
- "generators/simple_form_install/simple_form_install_generator.rb",
- "generators/simple_form_install/templates/simple_form.rb",
- "init.rb",
+ "lib/generators/simple_form_install/USAGE",
+ "lib/generators/simple_form_install/simple_form_install_generator.rb",
+ "lib/generators/simple_form_install/templates/simple_form.rb",
+ "lib/locales/en.yml",
"lib/simple_form.rb",
"lib/simple_form/action_view_extensions/builder.rb",
"lib/simple_form/action_view_extensions/form_helper.rb",
- "lib/simple_form/action_view_extensions/instance_tag.rb",
"lib/simple_form/components.rb",
"lib/simple_form/components/errors.rb",
"lib/simple_form/components/hints.rb",
@@ -40,9 +39,9 @@ Gem::Specification.new do |s|
"lib/simple_form/inputs/mapping_input.rb",
"lib/simple_form/inputs/priority_input.rb",
"lib/simple_form/inputs/text_field_input.rb",
- "lib/simple_form/locale/en.yml",
"lib/simple_form/map_type.rb",
- "lib/simple_form/version.rb"
+ "lib/simple_form/version.rb",
+ "lib/templates/erb/scaffold/_form.html.erb"
]
s.homepage = %q{http://github.com/plataformatec/simple_form}
s.rdoc_options = ["--charset=UTF-8"]
View
@@ -47,14 +47,19 @@ def with_input_for(object, attribute_name, type, options={})
assert_select 'input.decimal#user_age'
end
- test 'input should get options from column definition for string attributes' do
+ test 'input should use default text size for decimal attributes' do
+ with_input_for @user, :credit_limit, :decimal
+ assert_select 'input.decimal[size=50]'
+ end
+
+ test 'input should get maxlength from column definition for string attributes' do
with_input_for @user, :name, :string
assert_select 'input.string[maxlength=100]'
end
-
- test 'input should get options from column definition for decimal attributes' do
- with_input_for @user, :credit_limit, :decimal
- assert_select 'input.decimal[maxlength=15]'
+
+ test 'input should get size from column definition for string attributes respecting maximum value' do
+ with_input_for @user, :name, :string
+ assert_select 'input.string[size=50]'
end
# MappingInput

0 comments on commit 086b20a

Please sign in to comment.