Sha256: a9ee85cf134864aff792f38bec9544913b44cd7f37fab30ae27b1d6e6b671f45

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

module AbAdmin
  module Views
    module Inputs
      class DateTimePickerInput < ::SimpleForm::Inputs::Base
        def input(wrapper_options=nil)
          input_html_options[:value] ||= formatted_value
          input_html_options[:autocomplete] ||= 'off'
          input_html_classes << input_type
          @builder.text_field(attribute_name, input_html_options)
        end

        private

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

        def value_format
          case input_type
            when :date_picker
              '%Y-%m-%d'
            when :datetime_picker
              '%Y-%m-%d %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

7 entries across 7 versions & 1 rubygems

Version Path
ab_admin-0.11.0 lib/ab_admin/views/inputs/date_time_picker_input.rb
ab_admin-0.10.0 lib/ab_admin/views/inputs/date_time_picker_input.rb
ab_admin-0.9.0 lib/ab_admin/views/inputs/date_time_picker_input.rb
ab_admin-0.8.3 lib/ab_admin/views/inputs/date_time_picker_input.rb
ab_admin-0.8.2 lib/ab_admin/views/inputs/date_time_picker_input.rb
ab_admin-0.8.1 lib/ab_admin/views/inputs/date_time_picker_input.rb
ab_admin-0.8.0 lib/ab_admin/views/inputs/date_time_picker_input.rb