Sha256: f502b6cdd2c9e9030ee4268503dea191d5956e78039bda184ccd6a487f74b822

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

module ActiveAdmin
  module Inputs
    module Filters
      class DateRangeInput < ::Formtastic::Inputs::StringInput
        include Base

        def to_html
          input_wrapping do
            [ label_html,
              builder.text_field(gt_input_name, input_html_options(gt_input_name)),
              template.content_tag(:span, "-", class: "seperator"),
              builder.text_field(lt_input_name, input_html_options(lt_input_name)),
            ].join("\n").html_safe
          end
        end

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

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

        def input_html_options(input_name = gt_input_name)
          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,
            value: current_value ? current_value.strftime("%Y-%m-%d") : "" }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activeadmin-1.0.0.pre5 lib/active_admin/inputs/filters/date_range_input.rb