diff --git a/lib/datagrid/filters.rb b/lib/datagrid/filters.rb index c2a1831..9134af9 100644 --- a/lib/datagrid/filters.rb +++ b/lib/datagrid/filters.rb @@ -93,7 +93,8 @@ def filter_by_name(attribute) # Accepts a block or a symbol with an instance method name # * :unless - specify the reverse condition when the filter can be dislayed and used. # Accepts a block or a symbol with an instance method name - # * :input_options - options passed when rendering html input tag attributes + # * :input_options - options passed when rendering html input tag attributes. + # Use input_options.type to control input type including textarea. # * :label_options - options passed when rendering html label tag attributes # # See: https://github.com/bogdan/datagrid/wiki/Filters for examples diff --git a/lib/datagrid/form_builder.rb b/lib/datagrid/form_builder.rb index dd747b1..3b82522 100644 --- a/lib/datagrid/form_builder.rb +++ b/lib/datagrid/form_builder.rb @@ -10,11 +10,12 @@ module FormBuilder # * text_field for other filter types def datagrid_filter(filter_or_attribute, partials: nil, **options, &block) filter = datagrid_get_filter(filter_or_attribute) - options = { + self.send( + filter.form_builder_helper_name, filter, **filter.input_options, **add_html_classes(options, filter.name, datagrid_filter_html_class(filter)), - } - self.send(filter.form_builder_helper_name, filter, options, &block) + &block + ) end # @param filter_or_attribute [Datagrid::Filters::BaseFilter, String, Symbol] filter object or filter name @@ -28,7 +29,12 @@ def datagrid_label(filter_or_attribute, text = nil, **options, &block) def datagrid_filter_input(attribute_or_filter, **options) filter = datagrid_get_filter(attribute_or_filter) - text_field filter.name, value: object.filter_value_as_string(filter), **options + value = object.filter_value_as_string(filter) + if options[:type]&.to_sym == :textarea + text_area filter.name, value: value, **options, type: nil + else + text_field filter.name, value: value, **options + end end protected diff --git a/spec/datagrid/form_builder_spec.rb b/spec/datagrid/form_builder_spec.rb index 54f7d20..24b7b7e 100644 --- a/spec/datagrid/form_builder_spec.rb +++ b/spec/datagrid/form_builder_spec.rb @@ -88,16 +88,30 @@ class MyTemplate end end context "with input_options" do - let(:_filter) { :created_at } - let(:_grid) { - test_report do - scope {Entry} - filter(:created_at, :date, input_options: {type: :date}) - end - } - it { should equal_to_dom( - '' - )} + context "type is date" do + let(:_filter) { :created_at } + let(:_grid) { + test_report do + scope {Entry} + filter(:created_at, :date, input_options: {type: :date}) + end + } + it { should equal_to_dom( + '' + )} + end + context "type is textarea" do + let(:_filter) { :name } + let(:_grid) { + test_report do + scope {Entry} + filter(:name, :string, input_options: {type: :textarea}) + end + } + it { should equal_to_dom( + '