1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00

Merge branch 'master' into vs-html5-datetime-inputs

Conflicts:
	CHANGELOG.md
This commit is contained in:
Volmer Soares 2013-11-15 16:50:40 -02:00
commit b88ae876d2
6 changed files with 29 additions and 4 deletions

View file

@ -1,6 +1,7 @@
## master
### enchancements
### enhancements
* Add wrapper mapping per form basis [@rcillo](https://github.com/rcillo) and [@bernardoamc](https://github.com/bernardoamc)
* Map `datetime`, `date` and `time` input types to their respective HTML5 input tags
when HTML5 compatibility is enabled. To render the classic datetime selects in HTML5
form wrappers, set the `:html5` option to `false`. [@volmer](https://github.com/volmer)

View file

@ -66,7 +66,7 @@ SimpleForm.setup do |config|
config.error_notification_tag = :div
# CSS class to add for error notification helper.
config.error_notification_class = 'alert alert-error'
config.error_notification_class = 'error_notification'
# ID to add for error notification helper.
# config.error_notification_id = nil
@ -95,7 +95,7 @@ SimpleForm.setup do |config|
# config.label_text = lambda { |label, required| "#{required} #{label}" }
# You can define the class to use on all labels. Default is nil.
config.label_class = 'control-label'
# config.label_class = nil
# You can define the class to use on all forms. Default is simple_form.
# config.form_class = :simple_form

View file

@ -1,5 +1,8 @@
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
config.error_notification_class = 'alert alert-error'
config.label_class = 'control-label'
config.wrappers :bootstrap, tag: 'div', class: 'control-group', error_class: 'error' do |b|
b.use :html5
b.use :placeholder

View file

@ -107,6 +107,8 @@ module SimpleForm
# Custom wrappers for input types. This should be a hash containing an input
# type as key and the wrapper that will be used for all inputs with specified type.
# e.g { string: :string_wrapper, boolean: :boolean_wrapper }
# You can also set a wrapper mapping per form basis.
# e.g simple_form_for(@foo, wrapper_mapping: { checkbox: :bootstrap_checkbox })
mattr_accessor :wrapper_mappings
@@wrapper_mappings = nil

View file

@ -552,8 +552,16 @@ module SimpleForm
end
end
# Attempts to find a wrapper mapping. It follows the following rules:
#
# 1) It tries to find a wrapper for the current form
# 2) If not, it tries to find a config
def find_wrapper_mapping(input_type) #:nodoc:
SimpleForm.wrapper_mappings && SimpleForm.wrapper_mappings[input_type]
if options[:wrapper_mappings] && options[:wrapper_mappings][input_type]
options[:wrapper_mappings][input_type]
else
SimpleForm.wrapper_mappings && SimpleForm.wrapper_mappings[input_type]
end
end
# If cache_discovery is enabled, use the class level cache that persists

View file

@ -200,4 +200,15 @@ class WrapperTest < ActionView::TestCase
end
end
end
test 'use custom wrapper mapping per form basis' do
swap_wrapper :another do
with_concat_form_for @user, wrapper_mappings: { string: :another } do |f|
concat f.input :name
end
end
assert_select "section.custom_wrapper div.another_wrapper label"
assert_select "section.custom_wrapper div.another_wrapper input.string"
end
end