Merge remote-tracking branch 'origin/master' into rm-wrapper-classes
Conflicts: CHANGELOG.md lib/simple_form/inputs/boolean_input.rb
This commit is contained in:
commit
3f47fd0d23
|
@ -11,10 +11,6 @@ gemfile:
|
|||
- gemfiles/Gemfile.rails-4-0-stable
|
||||
- gemfiles/Gemfile.rails-4-1-stable
|
||||
- Gemfile
|
||||
matrix:
|
||||
allow_failures:
|
||||
- gemfile: Gemfile
|
||||
- gemfile: gemfiles/Gemfile.rails-4-1-stable
|
||||
notifications:
|
||||
email: false
|
||||
campfire:
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
* Add `include_default_input_wrapper_class` config [@luizcosta](https://github.com/luizcosta)
|
||||
* Map `datetime`, `date` and `time` input types to their respective HTML5 input tags
|
||||
when the `:html5` is set to `true` [@volmer](https://github.com/volmer)
|
||||
* Add `boolean_label_class` config.
|
||||
* Add `:html` option to include additional attributes on custom wrappers [remofritzsche](https://github.com/remofritzsche) and [@ulissesalmeida](https://github.com/ulissesalmeida)
|
||||
* Make possible to use the Wrappers API to define attributes for the components.
|
||||
See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
||||
|
||||
|
|
|
@ -346,14 +346,14 @@ used to retrieve label/value attributes for the `option` tags. Besides that, you
|
|||
### Priority
|
||||
|
||||
**Simple Form** also supports `:time_zone` and `:country`. When using such helpers, you can give
|
||||
`:priority` as option to select which time zones and/or countries should be given higher priority:
|
||||
`:priority` as an option to select which time zones and/or countries should be given higher priority:
|
||||
|
||||
```ruby
|
||||
f.input :residence_country, priority: [ "Brazil" ]
|
||||
f.input :time_zone, priority: /US/
|
||||
```
|
||||
|
||||
Those values can also be configured with a default value to be used site use through the
|
||||
Those values can also be configured with a default value to be used on the site through the
|
||||
`SimpleForm.country_priority` and `SimpleForm.time_zone_priority` helpers.
|
||||
|
||||
Note: While using `country_select` if you want to restrict to only a subset of countries for a specific
|
||||
|
@ -827,7 +827,7 @@ If you want to customize the custom _Form components_ on demand you can give it
|
|||
config.wrappers do |b|
|
||||
b.use :placeholder
|
||||
b.use :label_input
|
||||
b.wrapper :my_wrapper, tag: :div, class: 'separator' do |component|
|
||||
b.wrapper :my_wrapper, tag: :div, class: 'separator', html: { id: 'my_wrapper_id' } do |component|
|
||||
component.use :hint, wrap_with: { tag: :span, class: :hint }
|
||||
component.use :error, wrap_with: { tag: :span, class: :error }
|
||||
end
|
||||
|
|
|
@ -143,6 +143,9 @@ SimpleForm.setup do |config|
|
|||
# Default class for inputs
|
||||
# config.input_class = nil
|
||||
|
||||
# Define the default class of the input wrapper of the boolean input.
|
||||
config.boolean_label_class = 'checkbox'
|
||||
|
||||
# Defines if the default input wrapper class should be included in radio
|
||||
# collection wrappers.
|
||||
# config.include_default_input_wrapper_class = true
|
||||
|
|
|
@ -169,6 +169,10 @@ See https://github.com/plataformatec/simple_form/pull/997 for more information.
|
|||
mattr_accessor :include_default_input_wrapper_class
|
||||
@@include_default_input_wrapper_class = true
|
||||
|
||||
# Define the default class of the input wrapper of the boolean input.
|
||||
mattr_accessor :boolean_label_class
|
||||
@@boolean_label_class = 'checkbox'
|
||||
|
||||
## WRAPPER CONFIGURATION
|
||||
# The default wrapper to be used by the FormBuilder.
|
||||
mattr_accessor :default_wrapper
|
||||
|
|
|
@ -6,7 +6,7 @@ module SimpleForm
|
|||
|
||||
if nested_boolean_style?
|
||||
build_hidden_field_for_checkbox +
|
||||
template.label_tag(nil, class: "checkbox") {
|
||||
template.label_tag(nil, class: SimpleForm.boolean_label_class) {
|
||||
build_check_box_without_hidden_field(merged_input_options) +
|
||||
inline_label
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ module SimpleForm
|
|||
elsif nested_boolean_style?
|
||||
html_options = label_html_options.dup
|
||||
html_options[:class] ||= []
|
||||
html_options[:class].push(:checkbox)
|
||||
html_options[:class].push(SimpleForm.boolean_label_class) if SimpleForm.boolean_label_class
|
||||
|
||||
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ module SimpleForm
|
|||
end
|
||||
|
||||
def html_options(options)
|
||||
options[:"#{namespace}_html"] || {}
|
||||
(@defaults[:html] || {}).merge(options[:"#{namespace}_html"] || {})
|
||||
end
|
||||
|
||||
def html_classes(input, options)
|
||||
|
|
|
@ -128,6 +128,14 @@ class WrapperTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'custom wrappers can have additional attributes' do
|
||||
swap_wrapper :default, self.custom_wrapper_with_additional_attributes do
|
||||
with_form_for @user, :name
|
||||
|
||||
assert_select "div.custom_wrapper[title='some title'][data-wrapper='test']"
|
||||
end
|
||||
end
|
||||
|
||||
test 'custom wrappers on a form basis' do
|
||||
swap_wrapper :another do
|
||||
with_concat_form_for(@user) do |f|
|
||||
|
|
|
@ -128,6 +128,16 @@ class BooleanInputTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'input boolean with nested style works using :input only in wrapper config (no label_input), adding the extra label wrapper with custom class' do
|
||||
swap_wrapper do
|
||||
swap SimpleForm, boolean_style: :nested, boolean_label_class: 'foo' do
|
||||
with_input_for @user, :active, :boolean
|
||||
|
||||
assert_select 'label.boolean + input[type=hidden] + label.foo > input.boolean'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test 'input boolean with nested style works using :label_input in wrapper config, adding "checkbox" class to label' do
|
||||
swap_wrapper :default, self.custom_wrapper_without_top_level do
|
||||
swap SimpleForm, boolean_style: :nested do
|
||||
|
@ -138,6 +148,16 @@ class BooleanInputTest < ActionView::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'input boolean with nested style works using :label_input in wrapper config, adding custom class to label' do
|
||||
swap_wrapper :default, self.custom_wrapper_without_top_level do
|
||||
swap SimpleForm, boolean_style: :nested, boolean_label_class: 'foo' do
|
||||
with_input_for @user, :active, :boolean
|
||||
|
||||
assert_select 'input[type=hidden] + label.boolean.foo > input.boolean'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test 'input boolean without additional classes should add "checkbox" class to label' do
|
||||
swap_wrapper :default, self.custom_wrapper_without_top_level do
|
||||
swap SimpleForm, boolean_style: :nested, generate_additional_classes_for: [:input] do
|
||||
|
|
|
@ -138,6 +138,12 @@ module MiscHelpers
|
|||
end
|
||||
end
|
||||
|
||||
def custom_wrapper_with_additional_attributes
|
||||
SimpleForm.build tag: :div, class: 'custom_wrapper', html: { data: { wrapper: :test }, title: 'some title' } do |b|
|
||||
b.use :label_input
|
||||
end
|
||||
end
|
||||
|
||||
def custom_form_for(object, *args, &block)
|
||||
simple_form_for(object, *args, { builder: CustomFormBuilder }, &block)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue