Sha256: fbdf94b57ddf2e843596e12ce6c32bf004421f38ca5ac4a850474baa2df98586

Contents?: true

Size: 867 Bytes

Versions: 1

Compression:

Stored size: 867 Bytes

Contents

module ActiveAdmin
  module Inputs
    class DateTimePickerInput < ::Formtastic::Inputs::StringInput
      def input_html_options
        super.tap do |options|
          options[:class] = [options[:class], "date-time-picker"].compact.join(' ')
          options[:data] ||= {}
          options[:data].merge! datepicker_options
          options[:value] ||= value
        end
      end

      def value
        val = object.send(method)
        return DateTime.new(val.year, val.month, val.day, val.hour, val.min).strftime("%Y-%m-%d %H:%M") if val.is_a?(Time)
        return val if val.nil?
        val.to_s
      end

      private
      def datepicker_options
        options = self.options.fetch(:datepicker_options, {})
        options = Hash[options.map{ |k, v| [k.to_s.camelcase(:lower), v] }]
        { datepicker_options: options }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_admin_datetimepicker-0.1.0 lib/active_admin_datetimepicker/inputs/date_time_picker_input.rb