Merge pull request #630 from nashby/fix-issue-629
allow to add additional classes only for wrapper
This commit is contained in:
commit
1c9f1a5b99
|
@ -60,9 +60,7 @@ module SimpleForm
|
||||||
# Notice that html_options_for receives a reference to input_html_classes.
|
# Notice that html_options_for receives a reference to input_html_classes.
|
||||||
# This means that classes added dynamically to input_html_classes will
|
# This means that classes added dynamically to input_html_classes will
|
||||||
# still propagate to input_html_options.
|
# still propagate to input_html_options.
|
||||||
@html_classes = SimpleForm.additional_classes_for(:input) {
|
@html_classes = SimpleForm.additional_classes_for(:input) { additional_classes }
|
||||||
[input_type, required_class, readonly_class, disabled_class].compact
|
|
||||||
}
|
|
||||||
|
|
||||||
@input_html_classes = @html_classes.dup
|
@input_html_classes = @html_classes.dup
|
||||||
@input_html_options = html_options_for(:input, input_html_classes).tap do |o|
|
@input_html_options = html_options_for(:input, input_html_classes).tap do |o|
|
||||||
|
@ -80,6 +78,10 @@ module SimpleForm
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def additional_classes
|
||||||
|
[input_type, required_class, readonly_class, disabled_class].compact
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def add_size!
|
def add_size!
|
||||||
|
|
|
@ -24,7 +24,7 @@ module SimpleForm
|
||||||
|
|
||||||
def html_classes(input, options)
|
def html_classes(input, options)
|
||||||
css = options[:wrapper_class] ? Array.wrap(options[:wrapper_class]) : @defaults[:class]
|
css = options[:wrapper_class] ? Array.wrap(options[:wrapper_class]) : @defaults[:class]
|
||||||
css += SimpleForm.additional_classes_for(:wrapper) { input.html_classes }
|
css += SimpleForm.additional_classes_for(:wrapper) { input.additional_classes }
|
||||||
css << (options[:wrapper_error_class] || @defaults[:error_class]) if input.has_errors?
|
css << (options[:wrapper_error_class] || @defaults[:error_class]) if input.has_errors?
|
||||||
css << (options[:wrapper_hint_class] || @defaults[:hint_class]) if input.has_hint?
|
css << (options[:wrapper_hint_class] || @defaults[:hint_class]) if input.has_hint?
|
||||||
css.compact
|
css.compact
|
||||||
|
|
|
@ -46,6 +46,15 @@ class FormBuilderTest < ActionView::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'builder should allow to add additional classes only for wrapper' do
|
||||||
|
swap SimpleForm, :generate_additional_classes_for => [:wrapper] do
|
||||||
|
with_form_for @user, :post_count
|
||||||
|
assert_no_select "form input#user_post_count.string"
|
||||||
|
assert_no_select "form label#user_post_count.string"
|
||||||
|
assert_select "form div.input.string"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test 'builder should allow adding custom input mappings for integer input types' do
|
test 'builder should allow adding custom input mappings for integer input types' do
|
||||||
swap SimpleForm, :input_mappings => { /lock_version/ => :hidden } do
|
swap SimpleForm, :input_mappings => { /lock_version/ => :hidden } do
|
||||||
with_form_for @user, :lock_version
|
with_form_for @user, :lock_version
|
||||||
|
|
Loading…
Reference in New Issue