Skip to content

Commit

Permalink
Merge pull request heartcombo#1582 from betelgeuse/input_field_disabl…
Browse files Browse the repository at this point in the history
…ed_options

Improve disabled option to input_field
  • Loading branch information
feliperenan authored Jun 8, 2018
2 parents dbd2e19 + 1970d8b commit 01dabba
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/simple_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def input_field(attribute_name, options = {})
components = (wrapper.components.map(&:namespace) & ATTRIBUTE_COMPONENTS)

options = options.dup
options[:input_html] = options.except(:as, :boolean_style, :collection, :label_method, :value_method, :prompt, *components)
options[:input_html] = options.except(:as, :boolean_style, :collection, :disabled, :label_method, :value_method, :prompt, *components)
options = @defaults.deep_dup.deep_merge(options) if @defaults

input = find_input(attribute_name, options)
Expand Down
6 changes: 0 additions & 6 deletions test/form_builder/input_field_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@

# Tests for f.input_field
class InputFieldTest < ActionView::TestCase
def with_input_field_for(object, *args)
with_concat_form_for(object) do |f|
f.input_field(*args)
end
end

test "builder input_field only renders the input tag, nothing else" do
with_input_field_for @user, :name

Expand Down
13 changes: 13 additions & 0 deletions test/inputs/disabled_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,17 @@ class DisabledTest < ActionView::TestCase
with_input_for @user, :created_at, :datetime
assert_no_select 'select.datetime.disabled[disabled]'
end

test 'input_field collection allows disabled select' do
with_input_field_for @user, :description, collection: ['foo', 'bar'], disabled: true
assert_select 'select[disabled]'
assert_no_select 'option[disabled]'
end

test 'input_field collection allows individual disabled options' do
with_input_field_for @user, :description, collection: ['foo', 'bar'], disabled: 'bar'
assert_no_select 'select[disabled]'
assert_no_select 'option[disabled][value=foo]'
assert_select 'option[disabled][value=bar]'
end
end
6 changes: 6 additions & 0 deletions test/support/misc_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ def with_input_for(object, attribute_name, type, options = {})
f.input(attribute_name, options.merge(as: type))
end
end

def with_input_field_for(object, *args)
with_concat_form_for(object) do |f|
f.input_field(*args)
end
end
end

class CustomFormBuilder < SimpleForm::FormBuilder
Expand Down

0 comments on commit 01dabba

Please sign in to comment.