Update generated template.

This commit is contained in:
José Valim 2011-12-04 16:21:10 +01:00
parent 4391685bfd
commit d3ddd2a601
3 changed files with 18 additions and 26 deletions

View File

@ -3,9 +3,23 @@ SimpleForm.setup do |config|
# Wrappers are used by the form builder to generate a complete input.
# You can remove any component from the wrapper, change the order or even
# add your own to the stack. The options given to the wrappers method
# are used to wrap the whole input (if any exists).
# are used to wrap the whole input.
config.wrappers :class => :input, :error_class => :field_with_errors do |b|
## Configuration
# Determines whether to use HTML5 inputs (:email, :url, :search, :tel).
b.use :html5
## Extensions
# Calculate maxlength from validations for string inputs
b.use :maxlength
# Automatically use translation to retrieve a placeholder
b.use :placeholder
# Add the HTML5 required attribute to the input
b.use :required
# Add a pattern from format validations for string inputs
b.use :pattern
## Inputs
b.use :label_input
b.use :hint, :tag => :span, :class => :hint
b.use :error, :tag => :span, :class => :error
@ -54,12 +68,6 @@ SimpleForm.setup do |config|
# Default is enabled.
config.browser_validations = false
# Determines whether HTML5 types (:email, :url, :search, :tel) and attributes
# (e.g. required) are used or not. True by default.
# Having this on in non-HTML5 compliant sites can cause odd behavior in
# HTML5-aware browsers such as Chrome.
# config.html5 = true
# Collection of methods to detect if a file type was given.
# config.file_methods = [ :mounted_as, :file?, :public_filename ]
@ -77,8 +85,8 @@ SimpleForm.setup do |config|
# Default size for text inputs.
# config.default_input_size = 50
# When false, do not use translations for labels, hints or placeholders.
# config.translate = true
# When false, do not use translations for labels.
# config.translate_labels = true
# Automatically discover new inputs in Rails' autoload path.
# config.inputs_discovery = true

View File

@ -7,7 +7,7 @@ module SimpleForm
end
def has_required?
required_field? && html5? && SimpleForm.browser_validations
required_field?
end
end
end

View File

@ -243,22 +243,6 @@ class CollectionInputTest < ActionView::TestCase
assert_select 'input[type=radio][required]'
end
test 'when not using html5, input should not generate required html attribute' do
swap_wrapper do
with_input_for @user, :name, :string
assert_select 'input[type=text].required'
assert_no_select 'input[type=text][required]'
end
end
test 'when not using browser validations, input should not generate required html attribute' do
swap SimpleForm, :browser_validations => false do
with_input_for @user, :name, :string
assert_select 'input[type=text].required'
assert_no_select 'input[type=text][required]'
end
end
test 'collection input with select type should generate required html attribute only with blank option' do
with_input_for @user, :name, :select, :include_blank => true, :collection => ['Jose' , 'Carlos']
assert_select 'select.required'