diff --git a/lib/datagrid/filters.rb b/lib/datagrid/filters.rb index 7b3e9b9..dc58e80 100644 --- a/lib/datagrid/filters.rb +++ b/lib/datagrid/filters.rb @@ -45,7 +45,7 @@ def self.included(base) module ClassMethods - # Returns filter definition object by name + # @return [Datagrid::Filters::Filter] filter definition object by name def filter_by_name(attribute) if attribute.is_a?(Datagrid::Filters::BaseFilter) unless ancestors.include?(attribute.grid_class) @@ -151,12 +151,12 @@ def assets apply_filters(super, filters) end - # Returns filter value for given filter definition + # @return [Object] filter value for given filter definition def filter_value(filter) self[filter.name] end - # Returns string representation of filter value + # @return [String] string representation of filter value def filter_value_as_string(name) filter = filter_by_name(name) value = filter_value(filter) @@ -167,13 +167,12 @@ def filter_value_as_string(name) end end - # Returns filter object with the given name + # @return [Datagrid::Filters::Filter] filter object with the given name def filter_by_name(name) self.class.filter_by_name(name) end - # Returns assets filtered only by specified filters - # Allows partial filtering + # @return [Array] assets filtered only by specified filters def filter_by(*filters) apply_filters(scope, filters.map{|f| filter_by_name(f)}) end @@ -199,7 +198,7 @@ def default_filter self.class.default_filter end - # Returns all currently enabled filters + # @return [Array] all currently enabled filters def filters self.class.filters.select do |filter| filter.enabled?(self) diff --git a/lib/datagrid/form_builder.rb b/lib/datagrid/form_builder.rb index 4876d2a..d5a26eb 100644 --- a/lib/datagrid/form_builder.rb +++ b/lib/datagrid/form_builder.rb @@ -17,7 +17,7 @@ def datagrid_filter(filter_or_attribute, partials: nil, **options, &block) # @param filter_or_attribute [Datagrid::Filters::BaseFilter, String, Symbol] filter object or filter name # @param text [String, nil] label text, defaults to filter.header # @param options [Hash] options of rails label helper - # @return [String] a form label html for the corresponding filter name + # @return [String] a form label tag for the corresponding filter name def datagrid_label(filter_or_attribute, text = nil, **options, &block) filter = datagrid_get_filter(filter_or_attribute) label(filter.name, text || filter.header, **filter.label_options, **options, &block) @@ -27,7 +27,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) value = object.filter_value_as_string(filter) - if options[:type]&.to_sym == :textarea + type = options[:type]&.to_sym + if type == :"datetime-local" + datetime_local_field filter.name, **options + elsif type == :"date" + date_field filter.name, **options + elsif type == :textarea text_area filter.name, value: value, **options, type: nil else text_field filter.name, value: value, **options diff --git a/spec/datagrid/form_builder_spec.rb b/spec/datagrid/form_builder_spec.rb index e710fa1..56c9423 100644 --- a/spec/datagrid/form_builder_spec.rb +++ b/spec/datagrid/form_builder_spec.rb @@ -112,6 +112,32 @@ class MyTemplate '