Sha256: 644db3d91bce9838455e8856b1876b17cfd6cf6cf7504efa5eebebb76fda4473

Contents?: true

Size: 767 Bytes

Versions: 101

Compression:

Stored size: 767 Bytes

Contents

# frozen_string_literal: true

module ActionView
  module Helpers
    module Tags # :nodoc:
      class DatetimeField < TextField # :nodoc:
        def render
          options = @options.stringify_keys
          options["value"] ||= format_date(value)
          options["min"] = format_date(datetime_value(options["min"]))
          options["max"] = format_date(datetime_value(options["max"]))
          @options = options
          super
        end

        private
          def format_date(value)
            raise NotImplementedError
          end

          def datetime_value(value)
            if value.is_a? String
              DateTime.parse(value) rescue nil
            else
              value
            end
          end
      end
    end
  end
end

Version data entries

101 entries across 96 versions & 7 rubygems

Version Path
actionview-7.0.2 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.1 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.0 lib/action_view/helpers/tags/datetime_field.rb
actionview-6.1.4.4 lib/action_view/helpers/tags/datetime_field.rb
actionview-6.0.4.4 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.0.rc3 lib/action_view/helpers/tags/datetime_field.rb
actionview-6.1.4.3 lib/action_view/helpers/tags/datetime_field.rb
actionview-6.0.4.3 lib/action_view/helpers/tags/datetime_field.rb
actionview-6.0.4.2 lib/action_view/helpers/tags/datetime_field.rb
actionview-6.1.4.2 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.0.rc2 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.0.rc1 lib/action_view/helpers/tags/datetime_field.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/actionview-6.1.4.1/lib/action_view/helpers/tags/datetime_field.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/actionview-6.1.4.1/lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.0.alpha2 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.0.0.alpha1 lib/action_view/helpers/tags/datetime_field.rb
actionview-6.1.4.1 lib/action_view/helpers/tags/datetime_field.rb
actionview-6.0.4.1 lib/action_view/helpers/tags/datetime_field.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/actionview-6.1.4/lib/action_view/helpers/tags/datetime_field.rb
actionview-6.1.4 lib/action_view/helpers/tags/datetime_field.rb