Sha256: 85c247bdaa49e58e4bfc58544f5e2f4a9d979561df9ea2bc6063a9f03d7c8dad

Contents?: true

Size: 972 Bytes

Versions: 2

Compression:

Stored size: 972 Bytes

Contents

module AbAdmin
  module Views
    module Inputs
      class DateTimePickerInput < ::SimpleForm::Inputs::Base

        def input
          input_html_options[:value] ||= formated_value
          input_html_classes << input_type
          @builder.text_field(attribute_name, input_html_options)
        end

        private

        def formated_value
          object.send(attribute_name).try(:strftime, value_format)
        end

        def value_format
          case input_type
            when :date_picker
              '%d.%m.%Y'
            when :datetime_picker
              '%d.%m.%Y %H:%M'
            when :time_picker
              '%H:%M'
          end
        end

        def has_required?
          false
        end

        def label_target
          case input_type
            when :date, :datetime
              "#{attribute_name}_1i"
            when :time
              "#{attribute_name}_4i"
          end
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ab_admin-0.5.0 lib/ab_admin/views/inputs/date_time_picker_input.rb
ab_admin-0.4.0 lib/ab_admin/views/inputs/date_time_picker_input.rb