Class: ActiveAdmin::Inputs::Filters::DateRangeInput

Inherits:
Formtastic::Inputs::StringInput
  • Object
show all
Includes:
Base
Defined in:
lib/active_admin/inputs/filters/date_range_input.rb

Instance Method Summary collapse

Methods included from Base

#collection_from_options, #input_wrapping, #label_from_options, #required?, #wrapper_html_options

Methods included from Filters::FormtasticAddons

#column, #column_for, #has_predicate?, #humanized_method_name, #klass, #polymorphic_foreign_type?, #ransacker?, #reflection_for, #scope?, #searchable_has_many_through?, #seems_searchable?

Methods included from Formtastic::Inputs::Base

#input_wrapping

Instance Method Details

#gt_input_nameObject Also known as: input_name



16
17
18
# File 'lib/active_admin/inputs/filters/date_range_input.rb', line 16

def gt_input_name
  column && column.type == :date ? "#{method}_gteq" : "#{method}_gteq_datetime"
end

#gt_input_placeholderObject



39
40
41
# File 'lib/active_admin/inputs/filters/date_range_input.rb', line 39

def gt_input_placeholder
  I18n.t("active_admin.filters.predicates.from")
end

#input_html_options(input_name = gt_input_name, placeholder = gt_input_placeholder) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/active_admin/inputs/filters/date_range_input.rb', line 25

def input_html_options(input_name = gt_input_name, placeholder = gt_input_placeholder)
  current_value = begin
    #cast value to date object before rendering input
    @object.public_send(input_name).to_s.to_date
  rescue
    nil
  end
  { size: 12,
    class: "datepicker",
    maxlength: 10,
    placeholder: placeholder,
    value: current_value ? current_value.strftime("%Y-%m-%d") : "" }
end

#lt_input_nameObject



21
22
23
# File 'lib/active_admin/inputs/filters/date_range_input.rb', line 21

def lt_input_name
  column && column.type == :date ? "#{method}_lteq" : "#{method}_lteq_datetime"
end

#lt_input_placeholderObject



43
44
45
# File 'lib/active_admin/inputs/filters/date_range_input.rb', line 43

def lt_input_placeholder
  I18n.t("active_admin.filters.predicates.to")
end

#to_htmlObject



7
8
9
10
11
12
13
14
# File 'lib/active_admin/inputs/filters/date_range_input.rb', line 7

def to_html
  input_wrapping do
    [ label_html,
      builder.text_field(gt_input_name, input_html_options(gt_input_name, gt_input_placeholder)),
      builder.text_field(lt_input_name, input_html_options(lt_input_name, lt_input_placeholder)),
    ].join("\n").html_safe
  end
end