Class: Datagrid::Filters::EnumFilter

Inherits:
BaseFilter show all
Includes:
SelectOptions
Defined in:
lib/datagrid/filters/enum_filter.rb

Direct Known Subclasses

ExtendedBooleanFilter

Instance Attribute Summary

Attributes inherited from BaseFilter

#block, #grid_class, #name, #options

Instance Method Summary collapse

Methods included from SelectOptions

#include_blank, #prompt, #select, #select_values

Methods inherited from BaseFilter

#allow_blank?, #allow_nil?, #apply, #default, #default_scope?, #dummy?, #enabled?, #form_builder_helper_name, form_builder_helper_name, #format, #header, #input_options, #multiple?, #parse_values, #range?, #separator, #supports_range?, #type, #unapplicable_value?

Instance Method Details

#default_input_optionsObject



23
24
25
26
27
28
29
30
# File 'lib/datagrid/filters/enum_filter.rb', line 23

def default_input_options
  {
    **super,
    type: enum_checkboxes? ? "checkbox" : "select",
    multiple: multiple?,
    include_hidden: enum_checkboxes? ? false : nil,
  }
end

#enum_checkboxes?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/datagrid/filters/enum_filter.rb', line 47

def enum_checkboxes?
  options[:checkboxes]
end

#label_optionsObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/datagrid/filters/enum_filter.rb', line 32

def label_options
  if enum_checkboxes?
    # Each checkbox has its own label
    # The main label has no specific input to focus
    # See app/views/datagrid/_enum_checkboxes.html.erb
    { for: nil, **super }
  else
    super
  end
end

#parse(value) ⇒ Object



17
18
19
20
21
# File 'lib/datagrid/filters/enum_filter.rb', line 17

def parse(value)
  return nil if strict && !select.include?(value)

  value
end

#strictObject



43
44
45
# File 'lib/datagrid/filters/enum_filter.rb', line 43

def strict
  options[:strict]
end